以下代码段抛出在线路意外的标记:B:功能(FUNC,DATA1) https://jsbin.com/qobicahica/edit?html,js,output为什么这段代码会抛出意外的令牌?
var Funcb = (function()
{
return
{
b: function (func, data1)
{
alert(1);
}
};
})();
Funcb.b(1,1);
但是,在下面的教程工作的类似的例子:
https://toddmotto.com/everything-you-wanted-to-know-about-javascript-scope/
// define module
var Module = (function() {
return {
myMethod: function() {
console.log('myMethod has been called.');
}
};
})();
// call module + methods
Module.myMethod();
编辑: 返回后删除换行符后的作品,但为什么? JavaScript时是如此的宽容和松散类型,然后这是为什么不忽略:
var Funcb = (function()
{
return{
b: function (func, data1)
{
alert(1);
}
};
})();
https://jsfiddle.net/L01k684r/ – guest271314