In my example below based on some conditions I should either call foo method from my class or foo method from alternative.js; I'm assigning method in myFunc variable and call that variable however if I want to call foo method of myClass, it breaks because name gets undefined in MyClass.prototype.myclass. Is there any workaround here? Please let me know if you need more clarification:
MyClass.prototype.test = function(name) {
var myClass;
var myFunc;
shouldWork = true;
if(shouldWork){
p = require('alternative.js')
myFunc = p['foo'];
}else{
myClass= this.myclass(name);
myFunc = myClass['foo'];
}
myFunc('bar');// if "shouldWork" is true it works, but if it is false, it fails
//In other words, myClass.foo('bar') works but calling
//the variable which is set to myClass['foo']
}
MyClass.prototype.myclass = function(name) {
// Here I do some operations on name and if it is undefined it breaks!
// name gets undefined if you foo method of myClass if you have it in
//a variable, becuse it is not assiging name which is from prototype
}