Clarity in providing multiple parameters to the function in Javascript -
i provide multiple parameters javascript function, , having clarity regarding passed parameters, having function
var callme = function (param1, param2, param3) { console.log(param1 + ", " + param2 + ", " + param3) }
i call method callme() this, having in mind value of parameter initialization value itself:
callme(param1 = 1, param2 = 2, param3 = 3)
my goal have clarity when providing multiple parameters avoid confusion.
are there negative effects in example above, or may i'm trying reinvent wheel?
if you're not declaring params ahead of time var
, you're introducing global variables crazy. , can imagine it'd very, sloppy quickly. instead of doing that, use configuration object argument. though has own drawbacks, doing same thing while wrapping args in way doesn't (as say) reinvent wheel. so..
var f = function (config) { console.log(config.param1 + ", " + config.param2 + ", " + config.param3); } f({ param1: "foo", param2: "bar", param3: "baz" });
Comments
Post a Comment