我有机会自己测试它,而 jQuery 没有。这是我找到的解决方案:
var extendPrototype = function() {
var objectPrototype = Object.prototype,
hasOwnProperty = objectPrototype.hasOwnProperty,
isBuggy = !{valueOf: 0}.propertyIsEnumerable("valueOf"),
keys;
if(isBuggy)
keys = "constructor,hasOwnProperty,isPrototypeOf,propertyIsEnumerable,toLocaleString,toString,valueOf".split(",");
return function(prototype, object) {
var i,
key;
for(key in object)
if(hasOwnProperty.call(object, key))
prototype[key] = object[key];
if(isBuggy) {
i = 0;
for(i; key = keys[i]; i ++)
if(object[key] !== objectPrototype[key] || hasOwnProperty.call(object, key))
prototype[key] = object[key]
}
return prototype
}
}();