Module provides methods to create a new module. Any module created here has the ability of being extended by other modules. Existing properties are overridden.
Creating a module
- Source:
Examples
var NewModule = Module.create(function() {
this.value = 100;
});
NewModule.prototype.print = function() { console.log(this.value); };
var instance = NewModule();
instance.print(); // 100
Extending a module
var AnotherModule = Module.create();
AnotherModule.prototype.inc = function() { this.value++; };
var ExtendingModule = NewModule.extend(AnotherModule);
var instance = ExtendingModule();
instance.inc();
instance.print(); // 101