I am trying to manage my code in javascript.What I have done is created two classes.
(function(){
Main1 = function(){
return this;
}
Main1.prototype = {
Main1_method1 : function(){
},
Main1_method2 : function(){
}
}
})();
(function(){
Main2 =function(){
return this;
}
Main2.prototype = {
Main2_method1 : function(){
},
Main2_method2 : function(){
}
}
})();
var MyInstance1 = new Main1();
var MyInstance2 = new Main2();
Question : I want to invoke one method in another.I want to call Main2_method1 in Main1_method1,but i have no idea how to do it.
I can use the classical model(function.prototype.method = function(){}) or the prototypal model(object.create).But I want to do this using the above method.
Well, you'll need to call the method on the instance:
The only part you need to figure out is how
Main2access theMain1instance. You can simply put it globally which will work.But to be clean, you'd probably want to inject
Main1instance insideMain2on instantiation. Or, you keep them decoupled using an event hub.