Recommendation 5: Compare function statements and function expressions

  In the Javascript language, both function statement, but also a function expression, which is confusing because they look the same. Shorthand for a function statement var statement is a value of a function.

  The following statement:

function f(){}

It is equivalent to:

was f = function () {}

  The second form is recommended, because he made it clear that f is a variable that contains a function. To better use JavaScript, to understand the function that value is very important.

  function statement would be promoted in the resolution, which means that no matter where the function is placed, where the top-level scope when she will be moved to the definition. It relaxed the requirements for using the function must declare, of course, can also cause confusion.

  Official syntax conventions, a statement can not begin with a function expression, and beginning with the word function is a function of sentence statement. The solution to this problem is to function in a wide expression in parentheses.

(function(){}())

Guess you like

Origin www.cnblogs.com/chorkiu/p/12082154.html