Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JSHINT: The __proto__ property is deprecated

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]);
};
like image 679
cardeol Avatar asked Dec 06 '22 22:12

cardeol


1 Answers

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.

like image 166
James Allardice Avatar answered Dec 08 '22 13:12

James Allardice