UNPKG

1.99 kBMarkdownView Raw
1# ES6-Promise (subset of [rsvp.js](https://github.com/tildeio/rsvp.js))
2
3This is a polyfill of the [ES6 Promise](http://people.mozilla.org/~jorendorff/es6-draft.html#sec-promise-constructor). The implementation is a subset of [rsvp.js](https://github.com/tildeio/rsvp.js), if you're wanting extra features and more debugging options, check out the [full library](https://github.com/tildeio/rsvp.js).
4
5For API details and how to use promises, see the <a href="http://www.html5rocks.com/en/tutorials/es6/promises/">JavaScript Promises HTML5Rocks article</a>.
6
7## Downloads
8
9* [es6-promise](https://raw.githubusercontent.com/jakearchibald/es6-promise/master/dist/es6-promise.js)
10* [es6-promise-min](https://raw.githubusercontent.com/jakearchibald/es6-promise/master/dist/es6-promise.min.js)
11
12## Node.js
13
14To install:
15
16```sh
17npm install es6-promise
18```
19
20To use:
21
22```js
23var Promise = require('es6-promise').Promise;
24```
25
26## Usage in IE<9
27
28`catch` is a reserved word in IE<9, meaning `promise.catch(func)` throws a syntax error. To work around this, you can use a string to access the property as shown in the following example.
29
30However, please remember that such technique is already provided by most common minifiers, making the resulting code safe for old browsers and production:
31
32```js
33promise['catch'](function(err) {
34 // ...
35});
36```
37
38Or use `.then` instead:
39
40```js
41promise.then(undefined, function(err) {
42 // ...
43});
44```
45
46## Auto-polyfill
47
48To polyfill the global environment (either in Node or in the browser via CommonJS) use the following code snippet:
49
50```js
51require('es6-promise').polyfill();
52```
53
54Notice that we don't assign the result of `polyfill()` to any variable. The `polyfill()` method will patch the global environment (in this case to the `Promise` name) when called.
55
56## Building & Testing
57
58* `npm run build` to build
59* `npm test` to run tests
60* `npm start` to run a build watcher, and webserver to test
61* `npm run test:server` for a testem test runner and watching builder
62
\No newline at end of file