I'm using a "hasOwnProperty" function to extend compatibility but JSHint says that the Object.prototype.__proto__ is deprecated. There is a way to rewrite this function to avoid this warning and ensure the compatibility?
var hasOwnProperty = function (obj, prop) {
var proto = obj.__proto__ || obj.constructor.prototype;
return (prop in obj) &&
(!(prop in proto) || proto[prop] !== obj[prop]);
};
The "correct" way to do what you're trying to do is to use the Object.getPrototypeOf
function:
var proto = Object.getPrototypeOf(obj);
That's not supported in Internet Explorer 8 and below though so if you need to support old environments you could extend your test to include a check for that, and fall back to __proto__
where necessary.
That will obviously not avoid the JSHint warning though so you'll probably still want to set the proto
option to turn it off.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With