У меня проблемы с использованием метода декораторов в Javascript. В каждом источнике, который я читал на эту тему, говорится, что я должен иметь возможность создавать их так (обратите внимание на 3 аргумента):
const debug = (target, name, descriptor) => {
const method = descriptor.value; descriptor.value = function(...args){
console.log(`Calling ${name} with arguments: %o`, args);
let result = method.apply(this, args);
console.log(`result is %o`, result);
};
}
И потреблять их так:
@debug
message(obj) {
return 'testing'
}
Однако Когда я запускаю свой код, декоратор вызывается только с одним аргументом, дескриптор свойства:
Object [Descriptor] {
kind: 'method',
key: 'message',
placement: 'prototype',
descriptor: {
value: [Function: message],
writable: true,
configurable: true,
enumerable: false
}
}
undefined
undefined
My .babelrc
выглядит так:
{
"presets": [
["@babel/preset-env"]
],
"plugins": [
["@babel/plugin-proposal-decorators", { "decoratorsBeforeExport": true }],
["@babel/plugin-proposal-class-properties"],
["@babel/plugin-proposal-pipeline-operator", { "proposal": "minimal" }]
]
}
Любая подсказка, что я ' я делаю неправильно?