Note, Related Value of this inside object method?
Given
var obj = {
property: 5,
func1: function () {
console.log(this.property);
},
func2: () => {
console.log(this.property);
}
}
this
would be Window
at obj.func2()
.
When tried setting this
to obj
using Function.prototype.call()
, this
was still Window
var obj = {
property: 5,
func1: function () {
console.log(this.property);
},
func2: () => {
console.log(this.property);
}
}
obj.func2.call(obj);
Is this expected behaviour?
Why does
Function.prototype.call()
not set thecontext
ofobj.func2
toobj
?