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

前端 未结 6 624
慢半拍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:12

    The simplest explanation:

    function aaaaaaa(){
    

    Can be used before it is declarated:

    aaaaaaa();
    function aaaaaaa(){
    
    }
    

    But this doesn't work:

    aaaaaaa();
    aaaaaaa=function(){
    
    }
    

    That's because in the third code, you are assigning aaaaaaa to an anonymous function, not declaring it as a function.

提交回复
热议问题