来到这个JS片段,我真的不知道什么顺序的事情正在评估... 任何想法?括号将是有益的......Javascript订单评估的
return point[0] >= -width/2 - allowance &&
point[0] <= width/2 + allowance &&
point[1] >= -height/2 - allowance &&
point[1] <= height/2 + allowance;
来到这个JS片段,我真的不知道什么顺序的事情正在评估... 任何想法?括号将是有益的......Javascript订单评估的
return point[0] >= -width/2 - allowance &&
point[0] <= width/2 + allowance &&
point[1] >= -height/2 - allowance &&
point[1] <= height/2 + allowance;
等同于:
return
(point[0] >= ((-width/2) - allowance))
&& (point[0] <= ((width/2) + allowance))
&& (point[1] >= ((-height/2) - allowance))
&& (point[1] <= ((height/2) + allowance));
这个怎么样:'-width/2 - allowance'? '/'运算符优先于第二个'-' – 2011-04-01 13:49:57
美丽!谢谢! – whatsgoingon 2011-04-01 13:50:14
这将触发Javascript分号插入错误,除非您在与return语句相同的行上开始表达式。 – hugomg 2011-12-06 19:42:14
添加paratheses有的缩进应该更清楚:
return
point[0] >= (-width/2) - allowance
&&
point[0] <= (width/2) + allowance
&&
point[1] >= (-height/2) - allowance
&&
point[1] <= (height/2) + allowance;
https://developer.mozilla.org/en/JavaScript/Reference/Operators/Operator_Precedence
的初步认识运营商去按照这个顺序:一元否定,除法,加/减,关系(> =,< =),逻辑和。
return (point[0] >= ((-width/2) - allowance))
&& (point[0] <= ((width/2) + allowance))
&& (point[1] >= ((-height/2) - allowance))
&& (point[1] <= ((height/2) + allowance))
检查这个
function bob(n){
alert(n);
return n;
}
return bob(1) >= bob(2)/bob(3) - bob(4) &&
bob(5) <= bob(6)/bob97) + bob(8) &&
bob(9) >= bob(10)/bob(11) - bob(12) &&
bob(13) <= bob(14)/bob(15) + bob(16);
return (point[0]) >= (-width/2 - allowance) && (point[0] <= width/2 + allowance) && (point[1] >= -height/2 - allowance) && (point[1]) <= (height/2 + allowance);
FWIW:https://developer.mozilla.org/en/JavaScript/Reference/Operators/Operator_Precedence – Shog9 2011-04-01 13:47:32
现在,它的格式,它更有感!它最初看起来像这样,没有换行符:return point [0]> = -width/2 - allowance && point [0] <= width/2 + allowance && point [1]> = --height/2 - allowance && point [ 1] <=身高/ 2 +津贴; – whatsgoingon 2011-04-01 13:49:25
如果你已经破译了评估顺序,如果你将这个代码的功能联系起来,它可能会帮助未来的读者。 – elbillaf 2011-04-01 13:57:30