Skip to content

Instantly share code, notes, and snippets.

@terinjokes
Last active December 13, 2015 19:48
Show Gist options
  • Save terinjokes/4965516 to your computer and use it in GitHub Desktop.
Save terinjokes/4965516 to your computer and use it in GitHub Desktop.
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}
*/
@jdalton
Copy link

jdalton commented Feb 17, 2013

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