Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

How to implement the JavaScript member lookup mechanism

Shulou Source: shulou.com Published: 2022-05-31 10:37:11 10月25日 Update

This article "JavaScript member search mechanism how to achieve" most people do not understand, so the editor summarized the following content, detailed, clear steps, with a certain reference value, I hope you can get something after reading this article, let's take a look at this "JavaScript member search mechanism how to achieve" article it.

Description

1. When accessing the properties of an object (including methods), first investigate whether the object itself has the property.

2. If not, find the prototype (that is, the prototype prototype object pointed to by _ proto__).

3. If you haven't already found the prototype of the prototype object (the prototype object of Object).

4. And so on until Object is found.

Example

Function Star (uname, age) {this.uname = uname; this.age = age;} Star.prototype.sing = function () {console.log ('I can sing');} Star.prototype.sex = 'female'; / / Object.prototype.sex = 'male'; var ldh = new Star ('Andy Lau', 18) Ldh.sex = 'male'; console.log (ldh.sex); console.log (Object.prototype); console.log (ldh); console.log (Star.prototype); console.log (ldh.toString ()) The above is about the content of this article on "how to realize the JavaScript member search mechanism". I believe we all have a certain understanding. I hope the content shared by the editor will be helpful to you. If you want to know more about the relevant knowledge, please follow the industry information channel.

Tags: Content prototypes objects members mechanisms attributes articles knowledge articles and so on value most examples that is directions methods more steps knowledge points industries Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Huawei Docker vpn Shulou Tech Info OPPO Reno