我意识到这是一件毫无意义的事情,但我不明白为什么它不起作用。
var person = {
_name: "Steve",
doSomething: () => console.debug("Doing stuff with ", this._name)
}
“this”绑定到全局对象,而不是调用getName对象。我原以为上述内容相当于:
var person = {
_name: "Steve",
doSomething: function() { console.debug("Doing stuff with ", this._name) }
}
(我知道你应该这样写)
var person = {
_name: "Steve",
doSomething() {
console.debug("Doing stuff with ", this._name)
}
}