by tieTYT · 13y ago · 0 comments
In other words, what do I need to read before I can understand this article?
var myObj = {
foo: 'bar',
baz: function() {
console.log(this.foo); //would give you 'bar', as expected
//but if you have some code that changes the meaning of this, for example:
$('.button').click(function() {
console.log(this.foo); //undefined, since now "this" refers to the scope of the event's callback function
});
//but if you use bind:
$('.button').click((function() {
//now "this" is scoped to refer to the main object
console.log(this.foo); //gives you 'bar'
}).bind(this));
}
} let fib = (n) => {
if (n <= 1) return 1;
return fib(n - 1) + fib(n - 2};
}
I don't understand what this is showing. Wouldn't this code work the same way without fat arrows because there's no `this` being used anywhere?