开发者

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜