Function Expression

  One of the key characteristics of function declarations is function declaration hoisting, whereby function declarations are read before the code excutes. That means a function declaration may appear after code that calls it and still work:

1 sayHi();
2 function sayHi(){
3     alert("Hi!");
4 }

  Function expressions act like other expressions and, therefore, must be assigned before usage. The following causes an error:

1 sayHi();              // error - function doesn't exist yet
2 var sayHi = function(){
3     alert("Hi!");
4 };

  It's advisable to always use arguments.callee of the function name whenever you're writing recursive functions.

posted @ 2015-05-12 21:56  林大勇  阅读(204)  评论(0编辑  收藏  举报