Object methods, class methods, prototype methods && private properties, public properties, public static properties

Source: Internet
Author: User

"Content-type"Content="text/html; Charset=utf-8"> <title>test</title> //Object Constructorsfunction Atest (name) {//private properties, which can only be used inside the object constructor            varClassName ="atest"; //Public property, called after an object instantiation             This. Name =name; //Object Methods             This. Hello =function () {alert ( This. Name); Alert ( This. MSG ());//methods that are expanded using the prototype method can be used inside the classAlert This. Sex);//properties that are expanded using the prototype method can be used inside the classalert (atest.age);//a static property is called when the format is [object. Static property]            }        }        //the location of the class method (which is actually called directly by a static method): The external syntax format for the Person class: Class name. Method name = function ([parameter ...]) {statement line;}Atest.run =function () {alert ("I am the class method Run"); }        //Prototyping MethodsAtest.prototype.msg =function () {alert ("My name is:"+ This. name);//if the prototype method is called directly as a static method, THIS.name cannot be called        }        //public static properties outside of classAtest.age = -;//public static properties cannot use the "this. Property" and can only be called by using the object. property.//The prototype property, which is considered to be a property inside the class, uses the "this. prototype attribute", or it can be used as a public static property "object. prototype. prototype Properties"Atest.prototype.sex ="male"; Atest.run (); //class methods are also static methods that you can use directly with the object. static method ()Atest.prototype.msg ();//The prototype method is used as a static method when using the object. Prototype. Method () "alert (Atest.prototype.sex);//The prototype property is treated as a static property when you use the object. Prototype. Method () "        varA =NewAtest ("Chenm");//object methods and prototype methods need to instantiate objects before they can be usedA.hello ();//Object methods must instantiate objectsA.msg ();//The prototype method must instantiate the objectalert (a.age);//error, public static property can only be invoked using the object. Property//PS: As far as possible the method is defined as a prototype method, the prototype method avoids each call to the constructor of the property or method construction, save space, create objects faster.</script> </body>

Object methods, class methods, prototype methods && private properties, public properties, public static properties

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.