Javascript has always been written with a function oriented structure, as the script goes more dense it become complicate and harder to manage & extend. With Javascript module we can segregate these as logical modules. Here is an example how this can be done in JavaScript.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Jscript Module */ | |
var Module; | |
(function (Module) { | |
var exportClass = (function () { | |
function exportClass(message) { | |
this.greeting = message; | |
} | |
exportClass.prototype.greet = function () { | |
return "Hello, " + this.greeting; | |
}; | |
return exportClass; | |
})(); | |
Module.exportClass = exportClass; | |
})(Module || (Module = {})); | |
var greeter = new Module.exportClass("world"); |