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