MDN presents the following two examples of arrow functions
Example 1
var adder = {
base: 1,
addThruCall: function(a) {
var f = v => v + this.base;
var b = {
base: 2
};
return f.call(b, a);
}
};
console.log(adder.addThruCall(1)); // 2
Example 2
'use strict';
var obj = {
i: 10,
b: () => console.log(this.i, this),
c: function() {
console.log(this.i, this);
}
}
obj.b(); // prints undefined, Window {...} (or the global object)
obj.c(); // prints 10, Object {...}
Question
this.base
in Example 1 points toadder.base
this.i
from propertyb
in Example 2 resolves toundefined
If arrow functions do not have a this
value, should not this.base
also resolve to undefined
?