Difference between Object.key and Object.prototype.key
suggest changeUnlike in languages such as Python, static properties of the constructor function are not inherited by instances. Instances inherit from the constructor’s prototype, which inherits from the parent prototype. Properties set on the constructor itself stay there.
function Foo() {};
Foo.style = 'bold';
const foo = new Foo();
console.log(Foo.style); // 'bold'
console.log(foo.style); // undefined
Foo.prototype.style = 'italic';
console.log(Foo.style); // 'bold'
console.log(foo.style); // 'italic'
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents