[英]access this context in class decorator
我的裝飾
function vote(target) {
target.vote = (val = '') => {
console.log(target.name + val);
}
}
class Cat {
@vote
name = 'britanik';
meow() { return `${this.name} says Meow!`}
}
let garfield = new Cat();
garfield.vote('please .....');
但是target.name未定義為什么?
使target.vote成為正常功能,它應該可以正常工作。
function vote(target) {
target.vote = function(val=""){
console.log(this.name + val);
};
}
class Cat {
@vote name = "britanik";
meow() {
return `${this.name} says Meow!`;
}
}
let garfield = new Cat();
garfield.vote("please .....");
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.