Slide 8
Slide 8 text
// 1
function logged(target, name, descriptor) {
const original = descriptor.value;
descriptor.value = function wrapper(...args) {
console.log(`called ${name}`);
return original.call(this, ...args);
};
return descriptor;
}
// 2
function logged(original, { name }) {
return function wrapper(...args) {
console.log(`called ${name}`);
return original.call(this, ...args);
};
}
// 3
decorator @logged {
@wrap((original) => {
return function wrapper(...args) {
console.log(`called ${original.name}`);
return original.call(this, ...args);
};
})
}
// 4
function logged() {
return {
set(target, instance, name, original) {
return function wrapper(...args) {
console.log(`called ${name}`);
return original.call(this, ...args);
};
},
};
}
8