diff options
| author | Michael Williamson <mike@zwobble.org> | 2026-09-16 23:45:55 +0100 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2026-09-16 23:45:55 +0100 |
| commit | 28254f95c0792cb4370619c23ddf9d6d1b3c5e63 (patch) | |
| tree | 4543a61dbc83ca17c37285582881bea7a43107d9 | |
| parent | ffd37560dfc7a2b064f586b63982875f6db3da67 (diff) | |
Ensure also method is defined once
| -rw-r--r-- | lib/promises.js | 17 |
1 files changed, 9 insertions, 8 deletions
diff --git a/lib/promises.js b/lib/promises.js index 2a007c2..0c109c6 100644 --- a/lib/promises.js +++ b/lib/promises.js @@ -22,16 +22,17 @@ var props = exports.props = function(obj) { return addAlsoToPromise(result); }; -function addAlsoToPromise(promise) { - promise.also = function(func) { - var result = this.then(function(value) { - var returnValue = _.extend({}, value, func(value)); - return props(returnValue); - }); +var alsoMethod = function(func) { + var result = this.then(function(value) { + var returnValue = _.extend({}, value, func(value)); + return props(returnValue); + }); - return addAlsoToPromise(result); - }; + return addAlsoToPromise(result); +}; +function addAlsoToPromise(promise) { + promise.also = alsoMethod; return promise; } |
