Js object-oriented static method and static property instance analysis, js instance analysis

Source: Internet
Author: User

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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.