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} | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The behavior of
_.assign
is mentioned in the docs, with the fix in edge thecallback
behavior will not be used ifcallback
is the first or second arg.