admin管理员组

文章数量:1318336

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.

本文标签: Javascript get and set availability in browsersStack Overflow