Community Member Profile
- Profile: /members/6836-EtchEmKay.htm
- Comments: 3
- Points: 32
Recent Blog Comments By EtchEmKay
-
Overloading Javascript Functions Using A Sub-Function Approach
Posted on Sep 10, 2010 at 6:23 AM
A (very) quick prototype of a cleaner way of doing (strict) arguments check for both - type and count - Function.prototype.overload = function () { this.variants = this.variants || {}; var len = arguments.length, args = (Array.prototype.slice.call(arguments)),... read more »
-
Overloading Javascript Functions Using A Sub-Function Approach
Posted on Sep 10, 2010 at 1:51 AM
Oops .. the comment in the last line of code above should read "calls the 2-param version" .. which I think is a better implementation considering that the randRange() function essentially wants to deal with maximum of 2 arguments .. any more should be ignored.... read more »
-
Overloading Javascript Functions Using A Sub-Function Approach
Posted on Sep 10, 2010 at 1:43 AM
Another way of doing it (shorter version) - function randRange(){ (randRange[arguments.length] || randRange[2]).apply(this, arguments); } randRange[0] = function () { alert('Error: No parameters passed!'); return 0; }; randRange[1] = function (... read more »



