Coder Social home page Coder Social logo

es6-promise-polyfill's Introduction

NPM version Build Status

ES6 Promise polyfill

This is a polyfill of ES6 Promise. The implementation based on Jake Archibald implementation a subset of rsvp.js. If you're wanting extra features and more debugging options, check out the full library.

For API details and how to use promises, see the JavaScript Promises HTML5Rocks article.

Notes

The main target: implementation should be conformance with browser's implementations and to be minimal as possible in size. So it's strictly polyfill of ES6 Promise specification and nothing more.

It passes both Promises/A+ test suite and rsvp.js test suite. And as small as 2,6KB min (or 1KB min+gzip).

The polyfill uses setImmediate if available, or fallback to use setTimeout. Use setImmediate polyfill by @YuzuJS to reach better performance.

How to use

Browser

To install:

bower install es6-promise-polyfill

To use:

<script src="bower_components/es6-promise-polyfill/promise.min.js"></script>
<script>
  var promise = new Promise(...);
</script>

Node.js

To install:

npm install es6-promise-polyfill

To use:

var Promise = require('es6-promise-polyfill').Promise;
var promise = new Promise(...);

AMD

To install:

npm install es6-promise-polyfill

To use:

define(['es6-promise-polyfill'], function(Promise) {
  var promise = new Promise(...);
});

Usage in IE<9

catch is a reserved word in IE<9, meaning promise.catch(func) throws a syntax error. To work around this, use a string to access the property:

promise['catch'](function(err) {
  // ...
});

Or use .then instead:

promise.then(undefined, function(err) {
  // ...
});

License

Licensed under the MIT License.

es6-promise-polyfill's People

Contributors

lahmatiy avatar duzun avatar super-kamil avatar pwnall avatar natlibfi-arlehiko avatar

Watchers

James Cloos avatar papajia 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.