Javascript Find Arguments Passed to a Function
While working on Javascript optimization we can always use some functions having variable number of arguments.
E.g. if we come across a situation where we have to use one function to toggle visibility of the objects, but depending on clients input number of objects which needs to hide/show varies. In this case we can write a function as below where number of parameters can any variable.
//Assumption 0th parameter is boolean function toggle() { var args = toggle.arguments for (v = 1; v < args.length; v++) { obj = window.document.getElementById(args[v]); if (args[0]) obj.style.display = ""; else obj.style.display = "none"; } }
0 comments:
Post a Comment