参考:

 

里面的示例代码 有误。应该如下:

var lost = { 
     loc : "Island", 
     location : function () { return this.loc; }, 
     location :function (val) { this.loc = val; } 
}; 
lost.location = "Another island";

 

另外, IE8下 Object.defineProperty 定义到 String.prototype 上是报错的。

兼容一下:

jv.defineProperty = function (target, functionName, func, isEnumerable) {
    if (target[functionName]) return;
    if ($.browser.msie && (parseInt($.browser.version) < 9)) {
        target[functionName] = func;
    }
    else {
        Object.defineProperty(target, functionName, { value: func, enumerable: isEnumerable });
    }
}

 

IE8,不支持对 Object.prototype上进行定义:

Js 定义对象的方法_其他   作者:NewSea    

  如无特别标记说明,均为NewSea原创,版权私有,翻载必纠。欢迎交流,转载,但要在页面明显位置给出原文连接。谢谢。