16739ca54b8f3ddee0f5ae8e6e306689d879b709
[aai/esr-gui.git] /
1 # ES6-Promise (subset of [rsvp.js](https://github.com/tildeio/rsvp.js))
2
3 This 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) extracted by @jakearchibald, if you're wanting extra features and more debugging options, check out the [full library](https://github.com/tildeio/rsvp.js).
4
5 For 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/stefanpenner/es6-promise/master/dist/es6-promise.js)
10 * [es6-promise-min](https://raw.githubusercontent.com/stefanpenner/es6-promise/master/dist/es6-promise.min.js)
11
12 ## Node.js
13
14 To install:
15
16 ```sh
17 npm install es6-promise
18 ```
19
20 To use:
21
22 ```js
23 var Promise = require('es6-promise').Promise;
24 ```
25
26 ## Bower
27
28 To install:
29
30 ```sh
31 bower install es6-promise --save
32 ```
33
34
35 ## Usage in IE<9
36
37 `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.
38
39 However, please remember that such technique is already provided by most common minifiers, making the resulting code safe for old browsers and production:
40
41 ```js
42 promise['catch'](function(err) {
43   // ...
44 });
45 ```
46
47 Or use `.then` instead:
48
49 ```js
50 promise.then(undefined, function(err) {
51   // ...
52 });
53 ```
54
55 ## Auto-polyfill
56
57 To polyfill the global environment (either in Node or in the browser via CommonJS) use the following code snippet:
58
59 ```js
60 require('es6-promise').polyfill();
61 ```
62
63 Notice 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.
64
65 ## Building & Testing
66
67 You will need to have PhantomJS installed globally in order to run the tests.
68
69 `npm install -g phantomjs`
70
71 * `npm run build` to build
72 * `npm test` to run tests
73 * `npm start` to run a build watcher, and webserver to test
74 * `npm run test:server` for a testem test runner and watching builder