Get the App
SLTechnology News&Howtos  ›  Development  › 

How does js implement the default prototype of the prototype chain

Shulou Source: shulou.com Published: 2022-06-03 08:28:22 11月15日 Update

This article mainly introduces js how to achieve the default prototype of the prototype chain, has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let the editor take you to understand it.

1. By default, all reference type values inherit Object, which is also achieved through the prototype chain.

2. The default prototype of all functions is an instance of Object, so the default prototype contains an internal pointer to Object.prototype.

Example

/ / parent constructor function Father () {this.name = "father" this.house = "cottage"} / / prototype method Father.prototype.alertName = function () {console.log (this.name)} / / Child constructor function Children () {this.name = "children"} / / implement inheritance: prototype object of child constructor = instance object of parent constructor Children.prototype = new Father () / / create a subinstance let c = new Children () / / use the method on the Object prototype console.log (c.hasOwnProperty ('name')) / / true thank you for reading this article carefully I hope the article "how to achieve the default prototype of the prototype chain in js" shared by the editor is helpful to everyone. At the same time, I also hope that you can support us and pay attention to the industry information channel. More related knowledge is waiting for you to learn!

Tags: Prototypes functions examples articles objects methods values interests at the same time situations points pointers more friends knowledge types ribbons industries information information channels Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Technology Shulou Information MySQL MariaDB Redmi