This a extending code with some modification from Promises/A+ implementation.
It is designed to get the basics spot on correct, so that you can build extended promise implementations on top of it.
API
var promise = ; var promiseSomeTask = ;
Important Points
1 : promise --- is lowercase with the initial letter 2 : promise --- has only one method : then 3 : 1st argument for promise is function, and the 2nd can be ---true if u need catch some error when the sync codes running 4 : the promise is not a construtor but a factory 5 : when rejected, the onRejecting callback can receive 2 args ------ 1st : the error ------ 2nd : the value for the current resolved !
Inheritance
You can use inheritance if you want to create your own complete promise library with this as your basic starting point, perfect if you have lots of cool features you want to add. Here is an example of a promise library called Awesome
, which is built on top of Promise
correctly.
var promise = ; { if !this instanceof Awesome return fn; thisthen = then;} //Awesome extensionAwesomeprototype { return this};
N.B. if you fail to set the prototype and constructor properly or fail to do Promise.call, things can fail in really subtle ways.
License
MIT