2010-10-29 166 views
0
var p = this.getParams(); 
var pD = (o.params||{}); 
if (this.useJsonData) pD = (pD.jsonData||{}); 
this.cursor = (pD && pD[p.start]) ? pD[p.start] : 0; 

这两条线有什么区别。这段代码需要说明吗?

this.cursor = pD[p.start] || this.cursor || 0; 

第一个代码是罚款还是有任何错误。

回答

1

您的第二条线有问题。如果pD为空,该怎么办? 此外它会保持this.cursor的值为true(不为null或false,即)。

否则,它们是相同的。

+0

好吧,不一定完全相同。第一个总是改变'this.cursor',但第二个可能会使其保持不变。 – 2010-10-29 06:05:55

+0

这就是我写的:-) – 2010-10-29 06:06:42

+0

是的。阅读两遍,评论一次。 – 2010-10-29 06:12:05