First look at the following code:
The 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 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.
The 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 (' Twitter called ')};//bird is also an object, so it can have methods
Bird.jiao ()//calling method
</script>