简体   繁体   English

null / undefined将替换为IE9以外的所有浏览器中的全局对象

[英]null/undefined are replaced with the global object in all browsers except IE9

When I do this: 当我这样做:

Object.prototype.toString.call( null )

or this: 或这个:

Object.prototype.toString.call( )

the browsers return the following string value (in both cases): 浏览器返回以下字符串值(在两种情况下):

Chrome 9: [object global] Chrome 9: [object global]
Safari 5: [object DOMWindow] Safari 5: [object DOMWindow]
Firefox 3.6: [object Window] Firefox 3.6: [object Window]
Opera 11: [object Window] Opera 11: [object Window]

However in IE9 RC the return values are [object Null] and [object Undefined] respectively. 但是在IE9 RC中,返回值分别为[object Null][object Undefined]

The ES5 specification states: ES5规范规定:

NOTE The thisArg value is passed without modification as the this value. 注意thisArg值未经修改即作为此值传递。 This is a change from Edition 3, where a undefined or null thisArg is replaced with the global object and ToObject is applied to all other values and that result is passed as the this value. 这是对第3版的更改,其中未定义或null thisArg将替换为全局对象,ToObject将应用于所有其他值,并且结果将作为此值传递。

See here: http://es5.github.com/#x15.3.4.4 见这里: http//es5.github.com/#x15.3.4.4

Does this mean that IE9 is the only browser that follows this newly introduced rule? 这是否意味着IE9是唯一遵循这个新引入的规则的浏览器?

I'm going to go out on a limb and say yes . 我要走出去,说是的 ;) ;)

FYI, I just tested FF4, and it gives [object Null] and [object Undefined] 仅供参考,我刚刚测试了FF4,它给出了[object Null][object Undefined]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM