Don't say anything, directly on the code ... (Just so willful)
varAnimal =function(){};
Animal.name = "Dog";
varA =NewAnimal ();
Console.log (a.name);
Results:
It is obvious that such calls are not possible, so what if Console.log (animal.name)?
varAnimal =function(){
animal.name++;
};
Animal.name = 0;
//var a = new Animal ();
Console.log (animal.name);
A static method is a method that you can use without declaring an instance of the class
Nani? The result is this drop ..... For Mao?
What about this?
functionAnimal () {
//alert (animal.name);
This. Say =function(){
Console.log (Animal.name);
}
};
Animal.name = "Ev2le0";
varA =NewAnimal ();
A.say ();
The result is:
Nani, crying dizzy in the WC ...
Forget it or write a static method.
functionStaticclass () {};//declaration of a class
//add a static method to this class
Staticclass.staticmethod =function(){
Console.log ("This is a static method");
}
//declaring an instance method
StaticClass.prototype.instanceMethod =function(){
Console.log ("This is a instance method");
}
//try to call a static method, using 2 different ways
varA =NewStaticclass ();
A.staticmethod ();
The result is such a drop:
Try the class name again. Method Name Invocation Mode
functionStaticclass () {};//declaration of a class
//add a static method to this class
Staticclass.staticmethod =function(){
Console.log ("This is a static method");
}
//declaring an instance method
StaticClass.prototype.instanceMethod =function(){
Console.log ("This is a instance method");
}
//try to call a static method, using 2 different ways
varA =NewStaticclass ();
//A.staticmethod ();
Staticclass.staticmethod ();
The result is such a drop:
The invocation instance method can be used in the form of the class name. Method Name ()?
functionStaticclass () {};//declaration of a class
//add a static method to this class
Staticclass.staticmethod =function(){
Console.log ("This is a static method");
}
//declaring an instance method
StaticClass.prototype.instanceMethod =function(){
Console.log ("This is a instance method");
}
//try to call a static method, using 2 different ways
varA =NewStaticclass ();
//A.staticmethod ();
Staticclass.instancemethod ();
The result is such a drop:
Summarize:
1, the class name can be used for static methods. Method Name ()
2, the instance method can only be used to honestly use the object. The method name () is called in the form.
JS static properties and Static methods