i've been looking special argument and/or variable can i.e.:
function myfunction(arg1, arg2) { switch(arg2) { case firstchoice: // code break; case secondchoice: // code break; } }
and usage as:
myfunction('string', firstchoice);
so instance make different type of alerts output message in different styles:
function myalert(msg, type) { switch(type) { case style_one: alert("style one: " + msg); break; case style_two: alert("style two: *** " + msg + " ***"); } }
and use follow:
myalert("hello world", style_one);
or
myalert("hello world, again", style_two);
i know can't make switches that, , i've been looking around internet no answer on type called or if possible. maybe there workaround?
help appriciated.
best regards, christian
i don't see specific problem is, here. regular consts, created global variables in javascript.
var style_one = 1; var style_two = 2; function myalert(msg, type) { switch(type) { case style_one: alert("style one: " + msg); break; case style_two: alert("style two: *** " + msg + " ***"); } } myalert("test", style_two);
Comments
Post a Comment