// *** before: ***
//экспериментальные декораторы (experimentalDecorators: true) - не стандарт
//TC39,
// своя форма и несовместимость с будущим рантаймом
function logged(target: any, propertyKey: string,
descriptor: PropertyDescriptor) {
const original = descriptor.value;
descriptor.value = function (...args: any[]) {
console.log(`calling ${propertyKey}`);
return original.apply(this, args);
};
}
class Service {
@logged
run() {}
}
// *** in version 5.0: ***
// декораторы по стандарту TC39, без экспериментального флага
function loggedStd<This, Args extends any[], Return>(
target: (this: This, ...args: Args) => Return,
context: ClassMethodDecoratorContext
) {
return function (this: This, ...args: Args): Return {
console.log(`calling ${String(context.name)}`);
return target.call(this, ...args);
};
}
class ServiceStd {
@loggedStd
run() {}
}