I realise this is a pointless thing to do but I don't understand why it doesn't work.
var person = {
_name: "Steve",
doSomething: () => console.debug("Doing stuff with ", this._name)
}
"this" is bound to the global object and not the object getName was invoked on. I was expecting that the above is equivalent to :
var person = {
_name: "Steve",
doSomething: function() { console.debug("Doing stuff with ", this._name) }
}
(I know you should write it like this)
var person = {
_name: "Steve",
doSomething() {
console.debug("Doing stuff with ", this._name)
}
}
thisstill refers thewindowobject.person.getName()?function() { return console.debug("Doing stuff with ", this._name) }