以下是相关代码:
hasOwnProperty: function (obj, prop) {
var hasOwn = Object.prototype.hasOwnProperty,
proto;
if (hasOwn) {
return hasOwn.call(obj, prop);
} else {
proto = obj.__proto__ || obj.constructor.prototype;
return (prop in obj) && (!(prop in proto) || proto[prop] !== obj[prop]);
}
}
jslint在吐出此错误时失败:
Error:
Problem at line 653 character 29: Reserved name '__proto__'.
proto = obj.__proto__ || obj.constructor.prototype;
任何想法/解决方案?
答案 0 :(得分:0)
这似乎让jsLint保持安静:
hasOwnProperty: function (obj, prop) {
var hasOwn = Object.prototype.hasOwnProperty,
proto = '__proto__';
if (hasOwn) {
return hasOwn.call(obj, prop);
} else {
proto = obj[proto] || obj.constructor.prototype;
return (prop in obj) && (!(prop in proto) || proto[prop] !== obj[prop]);
}
}