论坛首页 Web前端技术论坛

Google Chrome 浏览器常见问题

浏览 2795 次
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
作者 正文
   发表时间:2008-10-08  
Google Chrome 雷区之一:与众不同的eval实现

运行代码:
javascript:var eval2 = eval;with({a:1})eval2("a+2")


在chrome上运行是要报错的。

记得ecma262 3rd上有一句,eval不应该通过引用别名调用(可能是处于优化的考虑吧)。
不过以往的实现中都没把这句话放在心上。

chrome虽然没有完全严格遵循ecma的的限制,不过,貌似还是充分利用理ecma的优化指导。
好同学,不愧是时下最快的js引擎。

貌似Chrome在eval的实现上,更加贴近标准了。
不过,这也许仅仅是chrome的一个bug,也许会在若干明主的口水淹没后,开始兼容更多的事实标准。

Google Chrome 雷区之二:警惕中文
var x = {
   "中文":"安全"
}

压缩后将变成:

var x={
中文:"危险"
}


基于rhino的压缩工具(JSA,YUI-Compressor),都会自动做上述优化,但是,貌似目前chrome对中文代码的支持有限



Google Chrome雷区之三--莫动arguments对象

arguments与参数变量的关联

javascript:+function(a){var a= 'false';alert(arguments[0])}(true)

输出的是:false,
firefox3 也是如此


javascript:+function(a){Array.prototype.splice.call(arguments,0,1);alert(a)}(1)
输出的是undefined 其他浏览器都不是。


再翻阅一下ECMA标准的描述

10.1.8 Arguments Object

    When control enters an execution context for function code, an arguments object is created and initialised as follows:

        * The value of the internal [[Prototype]] property of the arguments object is the original Object prototype object, the one that is the initial value of Object.prototype (see 15.2.3.1).
        * A property is created with name callee and property attributes { DontEnum }. The initial value of this property is the Function object being executed. This allows anonymous functions to be recursive.
        * A property is created with name length and property attributes { DontEnum }. The initial value of this property is the number of actual parameter values supplied by the caller.
        * For each non-negative integer, arg, less than the value of the length property, a property is created with name ToString(arg) and property attributes { DontEnum }. The initial value of this property is the value of the corresponding actual parameter supplied by the caller. The first actual parameter value corresponds to arg = 0, the second to arg = 1, and so on. In the case when arg is less than the number of formal parameters for the Function object, this property shares its value with the corresponding property of the activation object. This means that changing this property changes the corresponding property of the activation object and vice versa.

应该说,Google的实现是最贴近标准的。
而其他浏览器都或多或少没能实现。

这时为什么呢?自然有他的理由....


而我们能做的,那就是开发过程中,少动这个对象吧。
   发表时间:2008-10-09  
能把“安全”压成“危险”,的确够雷人的
0 请登录后投票
   发表时间:2008-12-23  
....楼上的回复也够雷人的...
0 请登录后投票
论坛首页 Web前端技术版

跳转论坛:
Global site tag (gtag.js) - Google Analytics