It's an agnostic, cross-browser and very lightweight library to help you to work with Promise in JavaScript.
P is compatible with the following browsers/versions:
- Google Chrome
- Firefox
- Safari
- IOS Safari
- Opera
- IE 7+
- P.init().
resolve(params)
- P.init().
reject(params)
- P.init().
then(callback)
Example
var context = {name: 'Evandro', year: 27};
var p = P.init(context);
window.load = function(delay) {
setTimeout(function(){
p.resolve();
}, delay);
return p;
};
window.load(200).then(function() {
console.log('name = ', this.name);
console.log('year = ', this.year);
});