This article describes the JS object-oriented static method and static properties. Share to everyone for your reference. The specific analysis is as follows:
First look at the following code:
Copy Code code 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 the Maque object, we can use Bird methods and properties
</script>
Think: Can we use bird methods and properties without creating a Maque object?
Knowledge points added:
(1) What is a function: A function is a variable, and a function is an object. The essence of a function is actually this:
var sum = new Function (' x ', ' y ', ' return x+y ');//x and y are parameters of the function, and "return x+y" is the function body.
(2) In JS, objects, functions, and arrays are created by the constructor. So, they're all objects. Since it is an object, the function must have attributes and methods.
Copy Code code 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 (' Twitter called ')};//bird is also an object, so it can have methods
Bird.jiao ()//calling method
</script>
I hope this article will help you with your JavaScript programming.