Js object-oriented static method and static property instance analysis, js instance analysis
This article describes the js object-oriented static methods and static attributes. Share it with you for your reference. The specific analysis is as follows:
First look at the following code:
Copy codeThe Code is as follows: <script type = "text/javascript">
Function Bird (){
This. wing = 2;
This. fly = function (){
Alert ("I am a bird, I can fly ");
}
}
Var maque = new Bird (); // after creating a maque object, we can use the Bird method and attributes.
</Script>
Thinking: Can we use the Bird method and attributes without creating a maque object?
Knowledge Point supplement:
(1) What is a function: a function is a variable, and a function is an object. The essence of a function is actually like this:
Var sum = new Function ('x', 'y', 'Return x + y'); // x and y are Function parameters, "return x + y" is the function body.
(2) In js, objects, functions, and arrays are created by constructors. Therefore, they are all objects. Since it is an object, the function must have attributes and methods.
Copy codeThe Code is as follows: <script type = "text/javascript">
Function Bird (){
This. wing = 2;
This. fly = function (){
Alert ("I am a bird, I can fly ");
}
}
Bird. jiao = function () {alert ('babbling)}; // The Bird function is also an object, so it can have a method
Bird. jiao (); // CALL THE METHOD
</Script>
I hope this article will help you design javascript programs.