The ways of declaration described above create the same function object type.
For example, if you define the function square, you could call it as follows: square 5 ; The preceding statement calls the function with an argument of 5. Because the function body is evaluated on runtime, this approach inherits many eval usage problems : security risks, harder debugging, no way to apply interpreter optimizations, no code auto-complete. To use a function, you must define it somewhere in the scope from which you wish to call it. Although a function expression creates a closure every time, the function body is not reparsed, so function expressions are still faster than "new Function In fact, during a function definition, we can pass in up to parameters! The function executes its statements and returns the value That is, the function forms a closure. MapReduce with function composition The principle of MapReduce is simple. The function name cannot be changed, while the variable the function is assigned to can be reassigned. Let's implement the traditional MapReduce. This is not different from storing references in other objects, but is often less obvious because one does not set the references directly and cannot inspect them. In the example below, we are setting the anonymous function object equal to a variable. Functions are objects. Let's go a step further and see another case where function composition can be very useful.
If we want the returned expression to wrap across multiple lines, we should start it at the same line as return. A function can call itself.
The created function is named, which means that name property of the function object holds its name. In some ways, recursion is analogous to a loop. However, in some situations it might be useful to set a different default value.
There are often cases where a function needs to be called dynamically, or the number of arguments to a function vary, or in which the context of the function call needs to be set to a specific object determined at runtime. A function can take multiple parameters separated by comma.
This eliminates the need of writing the same code again and again.
based on 103 review