In itself this sentence is very good explanation, the function has two main characteristics, quoted from the Chen Xin translation of "javascript mode":
1. The function is the first class of objects:
- Functions can be created dynamically at run time, and can also be created during program execution.
- Functions can be assigned variables, they can be copied to other variables, can be extended, in addition, except for a few special cases, functions can also be deleted.
- Can be passed as a parameter to other functions, and other functions can also be returned.
- Functions can have their own properties and methods.
2. The function provides scope
In JavaScript, you do not use the curly brace {} syntax to define the scope of a local variable, that is, the block does not create a scope. This also means that the variables declared in the If or for expressions will leapfrog the petition. So in order to prevent namespace pollution, self-executing anonymous functions are very much the way.
In StackOverflow http://stackoverflow.com/questions/245192/what-are-first-class-objects
Translate as follows:
Simply put, the first class of objects means that there is no difference between using and other objects.
A first class object is an entity that can be dynamically created, destroyed, passed, returned, and has the same status as other variables in the programming language.
The first class of objects has the following characteristics:
An anonymous literal is treated as an expression.
Can be stored in variables.
Can be stored in the data structure.
has a unique identity (can be distinguished by a function name)
Ability to perform the same comparison with other entities
can be used as parameters
Can be treated as a return value
Ability to dynamically create at run time
can print
Can read
Can be passed in different processes
Can be stored outside of the running process
"Functions in JavaScript are the first class of objects (first-class object)"