[removed] How is “function onload() {}” different from “onload = function() {}”?

前端 未结 6 670
慢半拍i
慢半拍i 2021-02-02 11:37

In the answers to this question, we read that function f() {} defines the name locally, while [var] f = function() {} defines it globally. That makes p

6条回答
  •  长发绾君心
    2021-02-02 12:39

    This generates an error:

    foo();
    var foo = function(){};
    

    This doesn't:

    foo();
    function foo(){}
    

    The second syntax is therefore nicer when you're using functions to modularize and organize your code, whereas the first syntax is nicer for the functions-as-data paradigm.

提交回复
热议问题