Multi-identity _javascript techniques for Javascript function objects

Source: Internet
Author: User
Copy Code code as follows:

function Flower ()
{
This.name= "Rose";
This.color= "Red";
}
Flower () as a constructor
var obj=new Flower ();
Output true, flower as a class reference
Alert (obj instanceof Flower);

The function keyword can declare a normal function, which is the same as the concept of functions in other languages. In addition, he can be used for the Declaration and implementation of classes, the constructors of objects, and references to classes.
In the example above, the Flower class is declared through the function keyword, and two property name and color are declared through the This keyword, and then the object constructor is flower when the Obj object is created, and the final use of the instanceof Keyword to determine if the Obj object is an instance of the Flower class, at which point the flower also acts as a class reference

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.