最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Javascript get and set availability in browsers - Stack Overflow

programmeradmin1浏览0评论

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";
    }
};

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";
    }
};
Share Improve this question edited Jan 26, 2015 at 1:51 Bergi 666k161 gold badges1k silver badges1.5k bronze badges asked May 16, 2011 at 3:22 AdamAdam 12.7k9 gold badges40 silver badges45 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 9

Here's a patibility table for you.

http://kangax.github./es5-pat-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)

  1. 暂无评论