javascriptecmascript-6standardjs

The '__proto__' property is deprecated with standard js


How to change the this.constructor.prototype.__proto__ = Error.prototype as per the standard js rules. Standard Js is throwing The '__proto__' property is deprecated. So what will be correct solution for the same.

Thanks in advance.


Solution

  • If you want to achieve (Prototypal) Inheritance, you can link the two objects as follows:

    this.constructor.prototype = Object.create(Error.prototype)
    

    Although many browsers have supported the usage of __proto__ as means of accessing the internal [[Prototype]] of an object, it has only been standardised in ES6 and its usage is still frowned upon.

    Similar effect can be achieved by using ES6's Object.setPrototypeOf(..).

    Consult this for more information.

    Hope this helps!