can someone please explain the following:
I want to add a function to the Array prototype. I'm doing this in two ways:
// option1
Array.prototype.myFunc1 = function() {
console.log(this);
}
// option2
Array.prototype.myFunc2 = () => {
console.log(this);
}
[1, 2].myFunc1();
[1, 2].myFunc2();
In option1 'this' is the array. In option2 'this' is an empty object. What's the difference?
Any thoughts appreciated C