本文介绍了Javascript获取和设置浏览器的可用性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
哪些浏览器不支持对象原型的get和set方法?我相信这是ES5的一个功能,我知道它在Chrome中工作,但我想知道是否可以安全地用于ajax应用程序。这里有一个例子:
var foo = function(){};
foo.prototype = {
get name(){
return this._name;
},
set name(n){
this._name = n || 酒吧;
}
};
解决方案
请参阅属性初始化程序中的 Getter
和 / code>行。
根据表格:
- Firefox 4
- Safari 5
- Chrome 7-11
其他浏览器(包括IE9)没有给予是
或否
,因此也许未经测试。我确定IE9支持它。
Which browsers do not support the get and set methods for object prototypes? I believe this is a feature of ES5, an I know it works in Chrome, but I am wondering if it is safe to use for ajax apps. Here's an example:
var foo = function () {};
foo.prototype = {
get name () {
return this._name;
},
set name (n) {
this._name = n || "bar";
}
};
解决方案
Here's a compatibility table for you.
http://kangax.github.com/es5-compat-table/
See the Getter in property initializer
and Setter in property initializer
rows.
According to the table:
- Firefox 4
- Safari 5
- Chrome 7-11
Other browsers (including IE9) are not given a Yes
or No
, so perhaps they're untested. I'm pretty sure IE9 supports it.
这篇关于Javascript获取和设置浏览器的可用性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!