Giter Club home page Giter Club logo

promise.js's Introduction

Promise.js

The ES6 Promise polyfill


This polyfill supports IE5+ browers, and it supports RequireJs.

Attentions

This polyfill has a little bit difference with the standard Promise. The standard method .then() and .catch() should be executed as a microtask, that means the callback function should be execeted when the stack is empty. But consider that the browsers, which do not support Promise, do not support microtask too, and the feature of microtask also can't be codes by JavaScript, it depends on the JavaScript engine, so this polyfill will executes .then() and .catch() as a task. Consequently, there may be some differences.

For example:

console.log("script start");

setTimeout(function () {
	console.log("timeout");
}, 0);

Promise.resolve().then(function () {
	console.log("promise1");
}, function () {}).then(function () {
	console.log("promise2");
}, function () {});

console.log("script end");

The majar browsers which accord W3C spec will log:

script start
script end
promise1
promise2
timeout

But use this polyfill to fixs those browsers which do not support Promise(Yeah, you konw I'm talking about IE...) will log:

script start
script end
timeout
promise1
promise2

The other difference is that the internal properties are exposed to outside, which means you can read the properties of Promise. For example, you could code promise["<state>"] to read the interval property, in IE9/10/11, you can't configure these internal properties, but in the below, you are able to change the value of that properties, but suggest that please do not do that.

promise.js's People

Contributors

sheltondong avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.