Prototype objects in JavaScript

Source: Internet
Author: User

<! DOCTYPE html>//prototypes        //the value of the prototype property of the constructor        functionPerson () { This. Name = "ADFS"; }        //Access Prototypes:        //Console.log (person.prototype);        //methods to add to the prototypePerson.prototype.say =function() {            //Console.log ("The method of the archetype of this matter");Console.log ( This. Name);        }; Person.prototype.name= "AAAAAAA"; //represents a non-public method that can be used, but there may be a problem        //person.prototype._init = function () {};        //to create an object by using a constructor function        varp =NewPerson (); //through the example of P, access to the method or attribute in the prototypeP.say ();        Person.prototype.say (); //the following two ways to call the difference:        //P.say ();        //Person.prototype.say ();        //         //1 Calling a method through an object is a method found through the property search principle and then called        //2 Direct access to the method, and then the call to the        //3 Method Internal this points to a different        //method inside the this: Who calls the method, this is the point to who        //__proto__        //you can also get to the prototype by leading to direct access        //as long as it is a non-standard attribute with __, it can no longer be used in the actual project        //The names of the methods written in some frames are also underlined:        //means that these methods are used internally by the framework.        //If you use it, the problem is, the framework is not responsible.        //p.__proto__Console.log (Person.prototype = = = p.__proto__);//true        //The prototype property of the constructor and the __proto__ of the object represent the same object        //It 's just a different way to access the object (prototype)P.__proto__.say (); //Console.log (p.__proto__);        //Two terms:        //prototype prototype Properties        //__proto__ Prototype Object        //It's like O1 and O2 are two variables, but these two variables are the same object        //var O1 = {};        //var O2 = O1;</script></body>

Prototype objects in JavaScript

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.