Last active
December 13, 2015 19:48
-
-
Save terinjokes/4965516 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
console.log(Q); | |
/* | |
>> function Q(value) { | |
>> return resolve(value); | |
>> } | |
*/ | |
var promise = _.extend({ | |
"ref": function() {} | |
}, Q); | |
console.log(promise); | |
console.log(promise.ref); | |
/* | |
* Expected: | |
>> function Q(value) { | |
>> return resolve(value); | |
>> } | |
>> | |
>> function() {} | |
* | |
* Actual: | |
>> Object {ref: function, longStackJumpLimit: 1, nextTick: function, defer: function, promise: function…} | |
>> | |
>> function() {} | |
*/ | |
/* | |
* While I have your attention, while debugging this I noticed something else | |
* fairly interesting: the new callback and thisArgs support in extend/assign, | |
* and merge causes issues with source objects like Q that are also functions. | |
*/ | |
var promise = _.extend({}, { | |
"ref": function() {} | |
}, Q); | |
console.log(promise); | |
/* | |
* Expected: | |
>> function Q(value) { | |
>> return resolve(value); | |
>> } | |
* | |
* Actual: | |
>> Object {ref: makePromise} | |
*/ |
Having seen issue thread for lodash/lodash#184 in my email, I figured as much. Now that I've upgraded (back) to edge, the following code works:
var promise = _.extend(_.bind(Q), Q, {
"ref": function() {}
});
Switching the order of the last two arguments does not work: I suppose because Lo-Dash has no way of determining if the function provided as the last argument (or second-to-last) is a callback
or sourceN
. I'm not sure how popular this is, though I believe it warrants a mention in the documentation.
The behavior of _.assign
is mentioned in the docs, with the fix in edge the callback
behavior will not be used if callback
is the first or second arg.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Your
_.extend
issue was addressed in c280347.