Home > Web Front-end > JS Tutorial > body text

Detailed explanation of js ordinary functions and constructors

小云云
Release: 2018-02-26 14:33:32
Original
2644 people have browsed it

This article mainly shares with you js ordinary functions and constructors, hoping to help you better understand what js ordinary functions and constructors are.

1. The constructor is also an ordinary function. It is created in the same way as an ordinary function, but the first letter of a constructor is customarily capitalized.

2. The difference between a constructor and an ordinary function is that the calling method is different. Same

3. How to call ordinary functions: directly call person();

4. How to call constructor: you need to use the new keyword to call new Person();

5. Execution process of the constructor

A. Immediately create a new object in the heap memory

B. Set the newly created object to this in the function

C. Execute the code in the function one by one

D. Use the newly created object as the return value

6. Ordinary function example: because there is no return value, it is undefined


7. Constructor example: The constructor will immediately create a new object and return the new object Value return


##8、Use instanceof to check whether an object It is an instance of a class, and returns true;

All objects are descendants of the Object object, so instanceof of any object and Object will return true


Related recommendations:

Code examples that explain the difference and usage of ordinary functions and arrow functions in JavaScript

Introduction to the use of ordinary functions in javascript_javascript skills

Comparison of ordinary functions and constructors in JavaScript_javascript skills

The above is the detailed content of Detailed explanation of js ordinary functions and constructors. For more information, please follow other related articles on the PHP Chinese website!

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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!