Yes, it's case sensitive (so obj.hasOwnProperty('x') !== obj.hasOwnProperty('X')
) You could extend the Object prototype (some people call that monkey patching):
Object.prototype.hasOwnPropertyCI = function(prop) {
return ( function(t) {
var ret = [];
for (var l in t){
if (t.hasOwnProperty(l)){
ret.push(l.toLowerCase());
}
}
return ret;
} )(this)
.indexOf(prop.toLowerCase()) > -1;
}
More functional:
Object.prototype.hasOwnPropertyCI = function(prop) {
return Object.keys(this)
.filter(function (v) {
return v.toLowerCase() === prop.toLowerCase();
}).length > 0;
};
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…