Javascript “Uncaught TypeError: object is not a function” associativity question

前端 未结 6 482
日久生厌
日久生厌 2020-12-02 14:57

Code is as follows:


    hello




        
6条回答
  •  猫巷女王i
    2020-12-02 15:44

    Your code experiences a case where the Automatic Semicolon Insertion (ASI) process doesn't happen.

    You should never rely on ASI. You should use semicolons to properly separate statements:

    var postTypes = new Array('hello', 'there'); // <--- Place a semicolon here!!
    
    (function() { alert('hello there') })();
    

    Your code was actually trying to invoke the array object.

提交回复
热议问题