Javascript IN运算符兼容性 [英] Javascript IN operator compatibility

查看:122
本文介绍了Javascript IN运算符兼容性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人可以告诉我哪个ECMA版本的IN运算符可用以及哪些浏览器(版本)支持它?

Can someone tell me since which ECMA version the IN operator is available and which browsers (versions) support it ?

说明:

IN运算符可以像下面一样使用:

The IN-operator can be used like the following:

var myObject = {
    Firstname: 'Foo',
    Lastname: 'Bar'
};

if('Lastname' in myObject){
    // Lastname is an attribute of myObject
}


推荐答案

它在 ECMAScript第3版。它适用于IE 5.5+以及所有正在使用的Firefox,Chrome,Opera和Safari版本。

It is defined in ECMAScript 3rd edition. It is available in IE 5.5+ and all in-use versions of Firefox, Chrome, Opera and Safari.

您可以安全地使用它,因为它知道它会起作用。

You can use it safe in the knowledge that it will work.

使用它来检查事件支持时,你应该小心谨慎。除旧版Firefox以外的所有实现都支持元素中的eventname作为DOM事件的测试。

You should err on the side of caution when using it to check event support. All implementations except older Firefox versions support "eventname" in element as a test for DOM events.

"onclick" in document.body; // -> false in old Fx, true in others
document.body.setAttribute("onclick", "");
typeof(document.body.onclick == "function"); // -> true in Fx

这篇关于Javascript IN运算符兼容性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆