1
var o = {}; // Creates a new object

defineProperty添加了数据属性描述符的对象属性示例

Object.defineProperty(o, "a", {value : 37,
                               writable : true,
                               enumerable : true,
                               configurable : true});

如何为 IE7-8 实现?(具有可写、可枚举、可配置的属性)

4

1 回答 1

0
if (!Object.defineProperty) {
        Object.defineProperty = function (obj, prop, descriptor) {
            if (arguments.length < 3) { // all arguments required
                throw new TypeError("Arguments not optional");
            }

            prop += ""; // convert prop to string
            ...     
于 2016-09-19T01:24:39.970 回答