Re:Advanced JavaScript Techniques
by willwagner on Friday October 09, 2009 @02:21PM
(#872113)
I use a similar technique when the number of optional arguments get out of control (i.e. if there is more than one optional argument). If you want to tight control, you can take advantage of the fact that a variable that is a function, the length member specifies the number of arguments declared as in:
(function(a,b,c){}).length == 3
Using that knowledge, you can do this at the top of a function:
(function(a,b,c){}).length == 3
Using that knowledge, you can do this at the top of a function:
if(arguments.callee.length > arguments.length){ throw "Required Parameter Missing"; }