arrow function、function.apply
An arrow function expression has a shorter syntax than a function expression and does not have its own this
, arguments, super, or new.target. These function expressions are best suited for non-method functions, and they cannot be used as constructors.
Syntax
Basic Syntax
(param1, param2, …, paramN) => { statements } (param1, param2, …, paramN) => expression // equivalent to: => { return expression; } // Parentheses are optional when there's only one parameter name: (singleParam) => { statements } singleParam => { statements } // The parameter list for a function with no parameters should be written with a pair of parentheses. () => { statements }
function.apply
The apply()
method calls a function with a given this
value, and arguments
provided as an array (or an array-like object).
Note: While the syntax of this function is almost identical to that of call()
, the fundamental difference is that call()
accepts an argument list, while apply()
accepts a single array of arguments.
Syntax
function.apply(thisArg, [argsArray])