You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: Readme.md
+2-49Lines changed: 2 additions & 49 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -5,6 +5,8 @@ This is a simple implementation of Promises. It is a super set of ES6 Promises
5
5
6
6
For detailed tutorials on its use, see www.promisejs.org
7
7
8
+
**N.B.** This promise exposes internals via underscore (`_`) prefixed properties. If you use these, your code will break with each new release.
9
+
8
10
[![travis][travis-image]][travis-url]
9
11
[![dep][dep-image]][dep-url]
10
12
[![npm][npm-image]][npm-url]
@@ -170,55 +172,6 @@ function awesomeAPI(foo, bar, callback) {
170
172
171
173
People who use typical node.js style callbacks will be able to just pass a callback and get the expected behavior. The enlightened people can not pass a callback and will get awesome promises.
172
174
173
-
## Extending Promises
174
-
175
-
There are three options for extending the promises created by this library.
176
-
177
-
### Inheritance
178
-
179
-
You can use inheritance if you want to create your own complete promise library with this as your basic starting point, perfect if you have lots of cool features you want to add. Here is an example of a promise library called `Awesome`, which is built on top of `Promise` correctly.
180
-
181
-
```javascript
182
-
varPromise=require('promise');
183
-
functionAwesome(fn) {
184
-
if (!(thisinstanceof Awesome)) returnnewAwesome(fn);
N.B. if you fail to set the prototype and constructor properly or fail to do Promise.call, things can fail in really subtle ways.
199
-
200
-
### Wrap
201
-
202
-
This is the nuclear option, for when you want to start from scratch. It ensures you won't be impacted by anyone who is extending the prototype (see below).
203
-
204
-
```javascript
205
-
functionUber(fn) {
206
-
if (!(thisinstanceof Uber)) returnnewUber(fn);
207
-
var _prom =newPromise(fn);
208
-
this.then=_prom.then;
209
-
}
210
-
211
-
Uber.prototype.spread=function (cb) {
212
-
returnthis.then(function (arr) {
213
-
returncb.apply(this, arr);
214
-
})
215
-
};
216
-
```
217
-
218
-
### Extending the Prototype
219
-
220
-
In general, you should never extend the prototype of this promise implimenation because your extensions could easily conflict with someone elses extensions. However, this organisation will host a library of extensions which do not conflict with each other, so you can safely enable any of those. If you think of an extension that we don't provide and you want to write it, submit an issue on this repository and (if I agree) I'll set you up with a repository and give you permission to commit to it.
0 commit comments