Home > Web Front-end > JS Tutorial > Multiple identities of Javascript function objects_javascript skills

Multiple identities of Javascript function objects_javascript skills

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-05-16 18:50:53
Original
1310 people have browsed it
Copy code The code is as follows:

function Flower()
{
this.name= "rose";
this.color="red";
}
//Flower() as constructor
var obj=new Flower();
//Output true, flower As a class reference
alert(obj instanceof Flower);

function keyword can declare ordinary functions, which is the same as the concept of functions in other languages. In addition, it can also be used for class declaration and implementation, object constructor and class reference.
In the above example, the Flower class is declared through the function keyword, and the two attributes name and color are declared through the this keyword; then when creating the obj object, Flower plays the role of the object constructor; finally, use The instanceof keyword determines whether the obj object is an instance of the Flower class. At this time, Flower plays the role of a class reference.
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Issues
What are JavaScript hook functions?
From 1970-01-01 08:00:00
0
0
0
What is JavaScript garbage collection?
From 1970-01-01 08:00:00
0
0
0
c++ calls javascript
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template