"Turn" JavaScript classes, prototypes, inherited understandings

Source: Internet
Author: User

Original: https://www.cnblogs.com/codernie/p/9098184.html

--------------------------------------------------------------------------------

1. What is the prototype of the class?
??? In JavaScript, whenever we define a constructor, the JavaScript engine automatically adds a prototype (also known as a prototype) to the class.
2. The object's Proto What is it?
??? In JavaScript, whenever we create an object using new, the JavaScript engine automatically adds a __proto__ property to the object and points it to its class prototype

//code 3.2function human (name) {this.name = Name}console.log (human.prototype) var person_test1 = new Human ( ' Test1 ') var person_ Test2 = new Human ( ' Test2 ')  Console.log (person_test1.__proto__) console.log (person_test2.__proto__) console.log (human.prototype = = = person_test1.__proto__) //Trueconsole.log (human.prototype = = = person_test2.__proto__) //true  

We will find that Human.prototype is an object, the human class is instantiated object Person_test1, Person_test2 has a property __proto__ is also an object, And they are all equal to Human.prototype, and we know that the equivalence of reference types in JavaScript means that they are pointing to the same object . So we can conclude that the __proto__ property of any instantiated object points to the prototype of its class.

"Turn" JavaScript classes, prototypes, inherited understandings

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.