以下函数中的表达式从右到左求值
function foo(){
var a = b = c;
}
所以就像是这样输入的
var a = (b = 0)
但是,当方法链接在一起时,它们是从左到右读取的。此对象中的方法...
var obj = {
value: 1,
increment: function () {
this.value += 1;
return this;
},
add: function (v) {
this.value += v;
return this;
},
shout: function () {
alert(this.value);
}
};
可以这样调用,从左到右求值
obj.increment().add(3).shout(); // 5
// 而不是一一调用
obj.increment();
obj.add(3);
obj.shout(); // 5
所以,我想我知道什么时候从左到右和从右到左阅读,但是有一个规则我需要知道我不知道吗?