Get the App
SLTechnology News&Howtos  ›  Development  › 

What does JavaScript prototype chain inheritance mean?

Shulou Source: shulou.com Published: 2022-06-03 10:05:58 11月15日 Update

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!

Tags: Prototypes objects instances functions properties content points pointers methods articles values interests guys buddies more knowledge types industries information information channels Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Information NVidia Linux Docker Microsoft