I have some questions about the way you can create modules in JavaScript. This is the syntax I found:
var Westeros;
(function (Westeros) {
(function (Structures) {
var Castle = (function () {
function Castle(name) {
this.name = name;
}
Castle.prototype.build = function () {
console.log("Castle " + this.name)
};
return Castle;
})();
Structures.Castle = Castle;
})(Westeros.Structures || (Westeros.Structures = {}));
var Structures = Westeros.Structures;
})(Westeros || (Westeros = {}));
var winterfell = new Westeros.Structures.Castle("Winterfell");
winterfell.build();
I took this code from Mastering Javascript Design Patterns. However I've tried to find an answer why you need this line:
var Structures = Westeros.Structures;
If you omit this line the code works as expected. Is there any explanation for this? Maybe to "reveal" the class?
Thanks!