Skip to content Skip to sidebar Skip to footer

Using Arrow Functions With .call()? "this" Varies Based On If In Devtools Or Iojs Locally? Should One Avoid Using Arrows With .call?

I've been running the below code and I notice that when running in devtools, obj.hi = 'default', while when running with iojs 3.3.1 with harmony arrow functions as an arg on my mac

Solution 1:

See Arrow Functions on MDN:

Since this is already bound lexically, invoking an arrow function through the call() or apply() methods can only pass in arguments, but has no effect on this:

So you can use call and apply with arrow functions, but you can't influence their this value: they take this from the containing scope. The fact that you can dynamically change this with io.js just indicates that it is broken with regards to this part of the specification.

Post a Comment for "Using Arrow Functions With .call()? "this" Varies Based On If In Devtools Or Iojs Locally? Should One Avoid Using Arrows With .call?"