I don't know how to explain the issue I am facing. I had made a small snippet. Please check below:
var Package = {};
Object.defineProperty(Object.prototype, 'inherit',
{
value: function(Parent, args)
{
var temp = function(){};
temp.prototype = Parent.prototype;
this.prototype = new temp();
this.uber = Parent.prototype;
this.prototype.constructor = this;
},
enumerable: false
});
var Module1 = Package.Module1 = function() {
// code;
};
Module1.prototype.method1 = function() {
};
var Module2 = Package.Module2 = function() {
// code;
};
Module2.prototype.method2 = function() {
};
var Module3 = Package.Module3 = function() {
// code;
};
// using custom : object.prototype.inherit
// Module3 inherit Module1 and 2;
Module3.inherit(Module1);
Module3.inherit(Module2);
Module3.prototype.method3 = function() {
};
//creating object
var mod = new Package.Module3();
mod.method1();
mod.method2();
mod.method3();
Creating the mod object I can access the method1,2 and 3. But actually I want to call the methods without creating the object, like Package.Module3.method1(); how is it possible?
Package.Module3have to be a constructor function? You could just create it as an object and assign the functions to it. Or you assign an instance ofModule3toPackage.Module3. It all depends on what else you want to do with it.