tags:

views:

93

answers:

2

So can this be done in Javascript?

type == 1 ? function1() : function2();
+5  A: 

Yes, that's valid code. It will invoke either function1() or function2(), but not both - depending on the value of type.

Jon Skeet
+1 It must be a slow day on SO when Jon Skeet and Ned Batchelder are answering JavaScript questions! :)
Andrew Hare
And Scala - http://stackoverflow.com/questions/1654664 :)
Jon Skeet
Got to hit that rep-cap, whatever it takes :D
Andrew Hare
+3  A: 

It won't invoke two functions. It will invoke one of your two functions.

Ned Batchelder