I'm using babel's require hook in node to leverage ES6 but I'm running into some challenges with arrow functions in bluebird promise chains.
I use .bind({})
at the top of my promise chain with an empty object to create shared state where I can store previous values until I need them further down the chain. Bluebird explains this usage as a "useful side purpose".
When I switch to arrow functions, I can no longer use shared state because arrow functions use lexical this
which is undefined
in babel (babel automatically runs in strict mode).
Working example: https://jsbin.com/veboco/edit?html,js,console
ES6 example (not working): https://jsbin.com/menivu/edit?html,js,console
Is there any way to take advantage of arrow functions in this situation? In my code I call these methods from within an object method - shouldn't this
be defined as the object from which the method is called?