diff options
Diffstat (limited to 'node_modules/when/lib/decorators/with.js')
| -rw-r--r-- | node_modules/when/lib/decorators/with.js | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/node_modules/when/lib/decorators/with.js b/node_modules/when/lib/decorators/with.js new file mode 100644 index 00000000..a0f05f0b --- /dev/null +++ b/node_modules/when/lib/decorators/with.js @@ -0,0 +1,38 @@ +/** @license MIT License (c) copyright 2010-2014 original author or authors */ +/** @author Brian Cavalier */ +/** @author John Hann */ + +(function(define) { 'use strict'; +define(function() { + + return function addWith(Promise) { + /** + * Returns a promise whose handlers will be called with `this` set to + * the supplied receiver. Subsequent promises derived from the + * returned promise will also have their handlers called with receiver + * as `this`. Calling `with` with undefined or no arguments will return + * a promise whose handlers will again be called in the usual Promises/A+ + * way (no `this`) thus safely undoing any previous `with` in the + * promise chain. + * + * WARNING: Promises returned from `with`/`withThis` are NOT Promises/A+ + * compliant, specifically violating 2.2.5 (http://promisesaplus.com/#point-41) + * + * @param {object} receiver `this` value for all handlers attached to + * the returned promise. + * @returns {Promise} + */ + Promise.prototype['with'] = Promise.prototype.withThis = function(receiver) { + var p = this._beget(); + var child = p._handler; + child.receiver = receiver; + this._handler.chain(child, receiver); + return p; + }; + + return Promise; + }; + +}); +}(typeof define === 'function' && define.amd ? define : function(factory) { module.exports = factory(); })); + |
