I follow the instructions in https://stackoverflow.com/a/881556/2704265 to add a namespace, as below:
var theme1 = {
document.addEventListener('DOMContentLoaded', function() {
});
};
However, after that, I will get Uncaught SyntaxError: Unexpected token '.' which point to the '.' after 'document', why?
Taking a look at the example given in the answer provided you have the following:
var yourNamespace = {
foo: function() {
},
bar: function() {
}
};
...
yourNamespace.foo();
The code you gave would need to look something more like this:
var themeNamespace = {
domLoader: function() {
document.addEventListener('DOMContentLoaded', function() {
});
},
}
Then run using themeNamespace.domLoader();