Written in front: This article introduces in detail the common writing methods and calling methods of 5 js functions. When I usually look at other people’s code, I always see various How to write js functions in different styles. I was confused, so I found some information and made a summary. Friends who need it can take a look and use it as a reference.
1. Conventional writing method (the most common one)
1 2 3 4 |
|
2. Anonymous function writing method (can be thought of as assigning a function to a variable)
1 2 3 4 |
|
3. Treat the method as an object
1 2 3 4 5 6 7 |
|
4. Add methods to the object in the constructor
Every object in javascript There is a prototype attribute. The explanation of the prototype attribute of an object in Javascript is: return a reference to the prototype of the object type.
1 2 3 4 5 6 7 |
|
5. Self-executing function
I found several different writing methods for js self-executing function. Let’s put them up for everyone to see
1 2 3 4 |
|
1 2 |
|
1 2 3 4 |
|
This article introduces the js function Common writing methods and calling methods, please pay attention to the php Chinese website for more related content.
Related recommendations:
The whole process of AJAX reading json with native JS
vue.js installation and configuration
JS implements browser printing and print preview
The above is the detailed content of Common writing methods and calling methods of js functions. For more information, please follow other related articles on the PHP Chinese website!