Javascript passing a function different sets of parameters -
so have function quite few parameters, example
function myfunction(height, width, name, surname, time){ ... }
the trouble want use function send different sets of parameters.
so be...
function myfunction(height, width, depth, name, surname, time){ ... }
the function used many tasks , don't want long list of parameters in function coupled lots of spaces in values list when function called.
i need more dynamic, ideally associative array passed function , variables created that.
because javascript doesn't have named arguments people use object "interfaces"
you can accept single argument object , have arguments keys.
function myfunction(options){ //access options.height , more... }
pass arguments packed in object function
myfunction({ height: 100, widht: 300, ... });
Comments
Post a Comment