Javascript get and set availability in browsers

旧街凉风 提交于 2019-12-10 03:31:57

问题


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

回答1:


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.



来源:https://stackoverflow.com/questions/6012897/javascript-get-and-set-availability-in-browsers

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!