The below snippet throws unexpected token at line: b: function (func, data1) https://jsbin.com/qobicahica/edit?html,js,output
var Funcb = (function()
{
return
{
b: function (func, data1)
{
alert(1);
}
};
})();
Funcb.b(1,1);
But, a similar example in below tutorial works:
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();
EDIT: Works after removing linebreaks after return, But why? When javascript is so forgiving and loosely typed, then why is this not ignored?:
var Funcb = (function()
{
return{
b: function (func, data1)
{
alert(1);
}
};
})();