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