Discuss / JavaScript / 为什么写成箭头函数不行,${this.name}是空的。。

为什么写成箭头函数不行,${this.name}是空的。。

Topic source
function Cat(name) {
    this.name=name;
}

Cat.prototype.say=(()=>`Hello, ${this.name}!`);

显示

"Hello, !"

Out

#2 Created at ... [Delete] [Delete and Lock User]

此时为全局对象得this


  • 1

Reply