Is there a difference between [removed] = stuff and [removed] = stuff()?

前端 未结 2 601
别跟我提以往
别跟我提以往 2021-01-25 19:45

I\'m most familiar with Python and somewhat with C, and when I see this syntax in JS it really confuses me

function begin () {
    console.log(\"done did it\");
         


        
2条回答
  •  粉色の甜心
    2021-01-25 20:15

    The right way is :

    window.onload = xxxx;
    

    the xxx must be a function.

    the first one:

    var fn = function() {
        alert("abc");
    }
    
    window.onload = fn;
    

    the other one:

    var fn = function() {
        var abc = "abc";
        return function () {
            alert(abc);
        }
    }
    window.onload = fn();
    

提交回复
热议问题