<body>
<script language="javascript">
window.tdiff = []; fred = function(a,b){return a-b;};
window.onload = function(e){
console.log("window.onload", e, Date.now() ,window.tdiff,
(window.tdiff[1] = Date.now()) && window.tdiff.reduce(fred) );
}
</script>
</body>
以上代码取自网站。
在 firefox->console 中,它显示:
window.onload load 1372646227664 [undefined, 1372646227664] 1372646227664
问题:
对于
window.tdiff->[undefined, 1372646227664]
,为什么不:[]
,因为当运行到 code: 时window.tdiff
,它仍然是一个空数组?对于,,,,
window.tdiff.reduce(fred)->1372646227664
应该是window.tdiff = [undefined, 1372646227664]
,为什么会显示?undefined - 1372646227664
NaN
1372646227664