0

考虑以下示例:

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}}
});

​我真的完全被 console.log 输出 #1 弄糊涂了。有两个问题需要回答:

  1. $_x第一个 console.log 输出中变量的真实状态是什么?

  2. 如果在使用 deferred 时,console.log 不是了解变量状态的安全方法,那么还有哪些更好的选择?

谢谢!

4

1 回答 1

0

必须使用JSON.stringify(),详见以下帖子:

console.log 中的错误?

于 2012-10-11T11:04:43.563 回答