Why is the function called? JavaScript / Window

前端 未结 2 1248
暖寄归人
暖寄归人 2021-01-19 03:15

I have the following code in my HTML file:

    

        
2条回答
  •  执笔经年
    2021-01-19 03:26

    Place the semi-colon after the function declaration:

        window.never = function() {
                 console.log('this function is never called');
        };
    

    It's because of the (...) directly afterwards that triggers the function call.

        window.never = function() {
                 console.log('this function is never called');
        }
        ( ... ) // <-- Triggers call of `window.never`
    

提交回复
热议问题