What does JavaScript prototype chain inheritance mean?
This article mainly introduces what JavaScript prototype chain inheritance refers to, the article is very detailed, has a certain reference value, interested friends must read it!
1. Each constructor has a prototype object that contains a pointer to the constructor, while the instance contains an internal pointer to the prototype object.
2. When the prototype object is equal to another type of instance, it inherits.
If a constructor instance object modifies property values and methods on the prototype object, it also affects other instance objects. And the property cannot be set.
Example
/ / the prototype chain inherits the properties and methods defined in function Animal () {} / /. All instance objects share Animal.prototype.name = 'xb';Animal.prototype.age = 2bot Animal.prototype.sayName = function () {console.log (this.name);} function Dog () {} Dog.prototype=new Animal;// completes a prototype chain inheritance Dog.prototype.constructor = Dog;// to reassign the constructor var D1 = new Dog () Console.log (D1); / / Dog {} console.log (d1.name); / / xbd1.sayName (); / / xb is all the content of the article "what does JavaScript prototype chain inheritance refer to". Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!