Can this be extended to include type matching?

 

Class is ‘debug’

Overloaded function is ‘error’

 

debug.error (1);     // Looks up a number error code and writes a string

debug.error (‘1’);  // Dumps the string

 

I know within the function ‘error’ you could do a typeOf, but can it be 
modified to intelligently decide what function to use based on the passed type?

 

Something like:

[ function error({a:’int’}){ //whatever },  function error([a:’str’}){ 
//whatever } ]

 

From: [email protected] [mailto:[email protected]] 
On Behalf Of ???? ????
Sent: Friday, March 11, 2011 5:50 AM
To: [email protected]
Subject: Re: [Moo] Re: Overloading method

 

a small fix:
http://jsfiddle.net/ariehg/ZDzPh/2/
the overloader will now use the first function (or if overloaded after 
construction the original method) if no match was found.

On Fri, Mar 11, 2011 at 12:48 PM, אריה גלזר <[email protected]> wrote:

As promissed:
http://jsfiddle.net/ariehg/ZDzPh/

a note on usage - since Class wraps it's methods, it is impossible to know 
function's arguments length after construction. To avoid this limitation, 
simply override the methods on a literal object before passing it to the Class 
constructor (as shown in the demo). This is actually a useful way of writing 
classes as it allows editor like eclipse to outline your methods.   

 

On Thu, Mar 10, 2011 at 8:30 PM, אריה גלזר <[email protected]> wrote:

Porting Resig's idea won't be very hard. It would require some monkey patching 
though. I might be able to upload something like it in a few hours

 

On Thu, Mar 10, 2011 at 3:29 PM, remram <[email protected]> wrote:

Hi Slik,
That is exactly, what I have looked for. But It's no Mootools. I found
also a solution from John Resig 
http://ejohn.org/blog/javascript-method-overloading/
. But is still no Mootools ;) I thought with Mootools would be
possible. Thank you anyway ;)





-- 

Arieh Glazer
אריה גלזר
052-5348-561
 <http://www.arieh.co.il> http://www.arieh.co.il
 <http://www.link-wd.co.il> http://www.link-wd.co.il

 




-- 

Arieh Glazer
אריה גלזר
052-5348-561
 <http://www.arieh.co.il> http://www.arieh.co.il
 <http://www.link-wd.co.il> http://www.link-wd.co.il

 




-- 

Arieh Glazer
אריה גלזר
052-5348-561
 <http://www.arieh.co.il> http://www.arieh.co.il
 <http://www.link-wd.co.il> http://www.link-wd.co.il

 

Reply via email to