Consider the following example:
var $_dfd = $.Deferred(),
$_x = {};
$_x = {
a: 1,
b: 2
};
console.log($_x); // Gives {a: 1, b: 2, more: {c: 3, d: 4}} <== Weirdness here
console.log($_x.a); // Gives 1
console.log($_x.more); // Gives undefined
$_dfd.pipe(function($_x) {
$_x.more = {
c: 3,
d: 4
};
return $_x;
});
$_dfd.resolve($_x).done(function($_x) {
console.log($_x); // Gives {a: 1, b: 2, more: {c: 3, d: 4}}
});
I am really totally baffled by console.log output #1. There are two questions that need to be answered:
What's the real state of the variable
$_x
at the first console.log output?If console.log is not a safe way to understand the state of variables when working with deferred, what are other better alternatives?
Thanks!