[英]Javascript ES6 Classes - Method cant access class property defined inside class constructor
[英]How can I access a property defined in a constructor of a class inside a method of the same class in Javascript without using this keyword?
我为我的代码配置了 eslint 检查,它向我抛出以下代码的以下错误:
错误 :
错误意外的“这个”没有无效的这个
代码例如:
class A {
constructor(name) {
this.name = name;
}
methodA = () => {
console.log(this.name);
}
}
如何修复代码以使其遵循 eslint 规则?
不是将箭头函数分配给属性,而是声明像methodA(name)
这样的方法完成了这项工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.