Skip to content Skip to sidebar Skip to footer

Arrow Functions Using Call, Apply, Bind - Not Working?

I'm being a bit puzzled when I try to convert a simple ES5 code to ES6. Let's say I have this block of code: var obj = {num: 2} var addToThis = function (a, b, c) { return this.

Solution 1:

Lambda functions (arrow functions) doesn't create new functional context and use context of a calling function.

So "this" refers to a parent context. If there's no 'num' variable than it's undefined.

Usually it's really convenient because most of the time you use one context instead of creating a new one in every function you create. In my opinion call/apply/bind is completely confusing and lambda functions makes it unnecessary.

Post a Comment for "Arrow Functions Using Call, Apply, Bind - Not Working?"