Js 定义对象的方法

原文:http://yiminghe.iteye.com/blog/696296

参考:http://www.cnblogs.com/yugege/p/4823863.html 

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

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上进行定义: http://www.cnblogs.com/_franky/archive/2011/04/27/2030766.html

alarm   作者:NewSea     出处:http://newsea.cnblogs.com/    QQ,MSN:iamnewsea@hotmail.com

  如无特别标记说明,均为NewSea原创,版权私有,翻载必纠。欢迎交流,转载,但要在页面明显位置给出原文连接。谢谢。
原文地址:https://www.cnblogs.com/newsea/p/2454640.html