Declaration of the "JavaScript summary" JavaScript class

Source: Internet
Author: User

Declaring the Person class
 function person(name, age){num =5;//No this modifier, belongs to class, equivalent to static variable in Java, class directly accesses     This. name = name;//has this modifier, belonging to the class object, called by the class object     This. Age = Age; This. info = function() {Alert"My message:"+ This. Name + This. Age +"<br/>"); }}alert (Person.num);varP1 =NewPerson (); alert (p1.info);varP2 =NewPerson (); alert (p2.info);
    • The above variables that do not have this modifier belong to the class. The equivalent of a static property in Java is called directly by the class name.
    • The following this modified variable is a property of the object that belongs to the class, and is the one that needs to be called by the
How the object method is commonly used declaratively

object's methods are generally not declared, because each time new comes out of an object, it opens up a memory space in memory, which is more memory-intensive

Therefore, the class plus method is generally used in the way of inheritance:

function(){    alert(this"正在慢慢溜达");}

At this time P1. P2 has a walk method,

Declaration of the "JavaScript summary" JavaScript class

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.