Can this be done in JavaScript?
type == 1 ? function1() : function2();
It won't invoke two functions. It will invoke one of your two functions.