Delay decorators
by shushanth pallegar
Babel + JSX
/*Delay decorator*/
const delay = (target, name, descriptor) => {
const originalFn = descriptor.value;
let delayExecution = (...args) => {
setTimeout(() => {
originalFn.apply(target, args);
},500);
}
descriptor.value = delayExecution;
}
class Animal {
constructor(name, sound) {
this.name = name;
this.sound = sound;
}
getName() {
return this.name;
}
makeSound() {
console.log(this.sound);
}
}
let Dog = new Animal('Rotweiler','BOW ! BOW! BOW!');
console.log(Dog.getName());
console.log(Dog.makeSound());