Richard Quadling
2008-Jan-02 15:43 UTC
Anonymous functions vs Named functions for event observation.
Hi. I''m sure I''ve asked this before, but I can''t remember. Is there any benefit in using named functions over anonymous functions for something like this ... document.observe ( ''dom:loaded'', function() { $$(''.EditNumber'') .invoke ( ''observe'', ''focus'', function(e) { this.writeAttribute(''Before'', this.value); } ) .invoke ( ''observe'', ''blur'', function(e) { this.value = parseFloat(this.value, 10).toFixed(2); if (isNaN(this.value)) { this.value = this.readAttribute(''Before''); } } ); } ); The idea is to allow a text input field to contain a number (in which case it will be 2DP) or text. This is working in FF and IE, so this is a stylistic question rather than a coding problem. -- ----- Richard Quadling Zend Certified Engineer : http://zend.com/zce.php?c=ZEND002498&r=213474731 "Standing on the shoulders of some very clever giants!" --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
Michael Peters
2008-Jan-02 15:52 UTC
Re: Anonymous functions vs Named functions for event observation.
Richard Quadling wrote:> I''m sure I''ve asked this before, but I can''t remember. > > Is there any benefit in using named functions over anonymous functions > for something like this ...If the function is ever going to be used in more than 1 place then use a named function. For anything else it''s probably just easier, more compact and more readable to use an anonymous function. Obviously if it get''s too large readability suffers. But it''s usually just a matter of opinion. -- Michael Peters Developer Plus Three, LP --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---