bluejava / zousan

A Lightning Fast, Yet Very Small Promise A+ Compliant Implementation
MIT License
127 stars 13 forks source link

Bug when #9

Closed tetratorus closed 7 years ago

tetratorus commented 7 years ago

var a = new Zousan(); var b = new Zousan(); a.then(b.resolve, b.reject); b.then(()=>console.log('hi'), ()=>console.log('bye'))

This doesn't work, it has something to do with call(_undefined, ...)

bluejava commented 7 years ago

Hi Leonard,

This breaks because you have passed function references into a.then to be subsequently called without their proper contexts.

One way to fix it is to pass in the functions bound to their context: a.then(b.resolve.bind(b), b.reject.bind(b));

Another is to use anonymous functions to do the same: a.then(x => b.resolve(x), x => b.reject(x));

But of course, the best approach to accomplish this behavior is to chain them, which achieves the exact same thing: b.resolve(a)

Thanks for taking the time to comment - and sorry for the delay in getting back to you!