Giter Site home page Giter Site 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

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

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

es6-promise-polyfill's Issues

Need to throw an exception when an error not catched.

new Promise(function(){throw 'test ex'});

I test it in ie9 Emulation. But no error throw.
Maybe a error can be throwed this way:

// some things bad happen, catched in `ex`
// now throw it
setTimeout(function(){throw ex},0);

I try to find where to insert these. But it's a little complex. Lots of callback >_<.

Please add license to the code

Hi!

I want to use your package, but since it is MIT licensed and your .js files does not have mention of license in them, I can't just throw them in my project and use, since MIT states that

A copy of the license and copyright notice must be included with the software.

Can you add something like

/*!
 * @overview es6-promise-polyfill - polyfill of ES6 Promise that is minimal as possible in size
 * @copyright Copyright (c) 2014 Roman Dvornov
 * @license   Licensed under MIT license
 *            See https://raw.githubusercontent.com/lahmatiy/es6-promise-polyfill/master/LICENSE
 * @version   v1.2.0
 */

Thank you!

new Function('return this')() is eval == bad code

I'm considering using this library in a Firefox Addon, but because of the last line my addon will be rejected by Mozilla Addon reviewers, as it is using eval.

Is there a special reason for that ?

Why not typeof global != 'undefined' ? global : this ?

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.