经常会遇到这样一个情况:浏览器弹出对话框,提示脚本运行时间过长,询问“停止”还是“继续”。那究竟各个浏览器是如何判断在什么时候才弹出此对话框呢?
IE:执行超过500W条JScript引擎语句出现提示。
Firefox:执行超过10秒出现提示。
Safari:执行超过5秒出现提示。
Opera:无论执行多久都不会出现提示,最有耐性。
Chrome:执行超过约8秒(估计值)出现提示。
注:当弹出类似alert的模式对话框的时候,是不计时。
扩展阅读:
《What determines that a script is long-running?》
...
23 条评论 »
2009-2-4 下午 - JS/Ajax/AS/Flex - javascript
年前在重写淘宝旺铺里的会员卡脚本的时候,无意中发现了一个有趣的事情。代码类似:
var associative_array = new Array();
associative_array["one"] = “1″;
associative_array["two"] = “2″;
associative_array["three"] = “3″;
if(associative_array.length > 0) {
// to do
}
会发现 associative_array.length 始终等于 0,当时有点迷惑,后来才知道这就像大家认为 IE 中支持 CSS 属性 display:inline-block 一样,纯属巧合和误解。
实际上(引自《JavaScript “Associative Arrays” Considered Harmful》):
JavaScript arrays (which are meant to be numeric) are often used to hold key/value pairs. This is bad practice. Object should be used [...]
...
23 条评论 »
2009-2-2 下午 - JS/Ajax/AS/Flex - Array - javascript