Sorry for the title of this question, but I don't found a better one.
INTRODUCTION
My goal is to create an object, and associate to every params a function. Very simple!
var canIDoThis = {
one: function(a, b, c){},
two: function(a){},
three: function(){}
}
I want call canIDoThis in this way
if(canIDoThis['one'](x, y, z)) {
// do somthing
}
if(canIDoThis['two'](w)) {
// do somthing
}
if(canIDoThis['three']()) {
// do somthing
}
If I have a var that can be "one", "two" or "three" I can use this canIDoThis in this way
// myVariable can be equalso to "one" or "two" or "three"
var myVarable;
if(canIDoThis[myVarable]()) {
// do somthing
}
MY PROBLEM
I'd like to manage all myVarable value.
Now if I call canIDoThis['four']() I get obviously Uncaught TypeError: undefined is not a function
MY QUESTION
Is there a way to prevent the default behaviour of Uncaught TypeError and return a default value? It would be cute if canIDoThis['four']() be interpretated as false or undefined
PS: I would like do this in pure JavaScript ;)