I have a javascript class:
MyClass = function(){
this.m_SomeData = 5;
};
and I have created some functions for that class:
MyClass.prototype.MyClassFunction_1 = function(arg){
// Some stuff that can return false
return true;
};
MyClass.prototype.MyClassFunction_2 = function(arg){
// Some stuff that can return false
return true;
};
MyClass.prototype.MyClassFunction_3 = function(arg){
// Some stuff that can return false
return true;
};
Later on I have created an instance of that class. (They could be combined into a single function but there are design issues that make it nicer to separate them):
var myInstance = new MyClass();
Now the tricky bit. In an 'if' statement I am doing the following (as well as other stuff).
var funcUse;
var arg = 3; // Some value created at run time)
if((funcUse = val === 0 ? MyClassFunction_1
: (val === 1 ? MyClassFunction_2 : MyClassFunction_3)) !== "undefined" &&
myInstance.funcUse(arg)){
}
The obvious problem is in the 'if' statement MyClassFunction_? are all undefined as they should be tied to an instance of the class, eg myInstance.MyClassFunction_?.
So how can this be done nicely in an if statement?