JavaScript has a prototypal inheritance model. Each object has an internal property that points to another object, called a prototype
.
That prototype object has a prototype of its own, and the whole sequence is called a prototype chain. When accessing a property or a
method of an object, if it is not found at the top level, the search continues through the object’s prototype and then further down the prototype
chain. This feature allows for very powerful dynamic inheritance patterns but can also lead to confusion when compared to the classic inheritance.
To simplify the access to the prototype of an object some browsers introduced the __proto__
property, which was later deprecated and
removed from the language. The current ECMAScript standard includes Object.getPrototypeOf
and Object.setPrototypeOf
static
methods that should be used instead of the __proto__
property.
let prototype = foo.__proto__; // Noncompliant: use Object.getPrototypeOf
foo.__proto__ = bar; // Noncompliant: use Object.setPrototypeOf
To fix your code replace __proto__
with calls to Object.getPrototypeOf
and Object.setPrototypeOf
static
methods.
let prototype = Object.getPrototypeOf(foo);
Object.setPrototypeOf(foo, bar);