Why is this an issue?
JavaScript has a prototypical 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.getPrototype
and Object.setPrototype
static
methods that should be used instead of the __proto__
property.
let prototype = foo.__proto__; // Noncompliant: use Object.getPrototype
foo.__proto__ = bar; // Noncompliant: use Object.setPrototype
To fix your code replace __proto__
with calls to Object.getPrototype
and Object.setPrototype
static
methods.
let prototype = Object.getPrototype(foo);
Object.setPrototype(foo, bar);
Resources
Documentation