问题

var date = new Date()
(function(){
    console.log("anonymous function")
}())

报错:

Uncaught TypeError: (intermediate value) is not a function

解决办法

手动添加分号

var date = new Date(); //Add ;
(function(){
    console.log("anonymous function")
}())

原因

JavaScript 的自动添加分号机制
详情见: https://www.ecma-international.org/ecma-262/5.1/#sec-7.9

写代码还是主动添加分号,养成好习惯~~~


zeroyl
156 声望2 粉丝