Version 1
[yaffs-website] / node_modules / es6-promise / README.md
1 # ES6-Promise (subset of [rsvp.js](https://github.com/tildeio/rsvp.js)) [![Build Status](https://travis-ci.org/stefanpenner/es6-promise.svg?branch=master)](https://travis-ci.org/stefanpenner/es6-promise)
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 27.86 KB (7.33 KB gzipped)](https://raw.githubusercontent.com/stefanpenner/es6-promise/master/dist/es6-promise.js)
10 * [es6-promise-auto 27.78 KB (7.3 KB gzipped)](https://raw.githubusercontent.com/stefanpenner/es6-promise/master/dist/es6-promise.auto.js) - Automatically provides/replaces `Promise` if missing or broken.
11 * [es6-promise-min 6.17 KB (2.4 KB gzipped)](https://raw.githubusercontent.com/stefanpenner/es6-promise/master/dist/es6-promise.min.js)
12 * [es6-promise-auto-min 6.19 KB (2.4 KB gzipped)](https://raw.githubusercontent.com/stefanpenner/es6-promise/master/dist/es6-promise.auto.min.js) - Minified version of `es6-promise-auto` above.
13
14 ## Node.js
15
16 To install:
17
18 ```sh
19 npm install es6-promise
20 ```
21
22 To use:
23
24 ```js
25 var Promise = require('es6-promise').Promise;
26 ```
27
28 ## Bower
29
30 To install:
31
32 ```sh
33 bower install es6-promise --save
34 ```
35
36
37 ## Usage in IE<9
38
39 `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.
40
41 However, please remember that such technique is already provided by most common minifiers, making the resulting code safe for old browsers and production:
42
43 ```js
44 promise['catch'](function(err) {
45   // ...
46 });
47 ```
48
49 Or use `.then` instead:
50
51 ```js
52 promise.then(undefined, function(err) {
53   // ...
54 });
55 ```
56
57 ## Auto-polyfill
58
59 To polyfill the global environment (either in Node or in the browser via CommonJS) use the following code snippet:
60
61 ```js
62 require('es6-promise').polyfill();
63 ```
64
65 Alternatively
66
67 ```js
68 require('es6-promise/auto');
69 ```
70
71 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.
72
73 ## Building & Testing
74
75 You will need to have PhantomJS installed globally in order to run the tests.
76
77 `npm install -g phantomjs`
78
79 * `npm run build` to build
80 * `npm test` to run tests
81 * `npm start` to run a build watcher, and webserver to test
82 * `npm run test:server` for a testem test runner and watching builder