Javascript get and set availability in browsers
Which browsers do not support t开发者_Go百科he 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.
精彩评论