This article describes the static methods and static properties of js object-oriented. Share it for your reference. The specific analysis is as follows:
Let's look at the following code first:
Copy the 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's methods and properties
</script>
Thinking: Can we use Bird's methods and properties without creating maque objects?
Supplements of knowledge points:
(1) What is a function: a function is a variable, and a function is also an object. The essence of a function is actually like this:
var sum = new Function('x','y','return x+y');//x and y are parameters of the function, and "return x+y" is the body of the function.
(2) In js, objects, functions and arrays are all created by constructors. So, they are all objects. Since it is an object, the function must have properties and methods.
Copy the 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('t chirping')};//Bird function is also an object, so it can have methods
Bird.jiao();//Calling method
</script>
I hope this article will be helpful to everyone's JavaScript programming.