I know about using .call()
and .apply()
to set the this
for a function call, but can I use it for a lambda?
Consider this example from the MDN webdoc for Function.prototype.call:
function greet1() {
var reply = [this.person, 'Is An Awesome', this.role].join(' ');
console.log(reply);
}
let greet2 = () => {
var reply = [this.person, 'Is An Awesome', this.role].join(' ');
console.log(reply);
}
var i = {
person: 'Douglas Crockford', role: 'Javascript Developer'
};
greet1.call(i); // Douglas Crockford Is An Awesome Javascript Developer
greet2.call(i); // Is An Awesome Javascript Developer
Why doesn't the greet2
call work the same was as greet1
and is there a way to set this
in the case of greet2
?