Because of some visual requirements for the div that contains the autocomplete choices, I want to execute some javascript every time updateChoices is executed. But I don''t want to modify controls.js to avoid maintenance headaches. I started out with code like this: var _updateChoices = Autocompleter.Base.prototype.updateChoices; Autocompleter.Base.prototype.updateChoices = function(choices) { _updateChoices(choices); }; but I end up getting a "too much recursion" error. Is there a clean way to do something like this? Thanks, dc --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Justin Perkins
2008-Mar-18 22:27 UTC
Re: Execute my own javascript on Autocompleter functions
You should try the wrap function technique... Autocompleter.Base.prototype.updateChoices Autocompleter.Base.prototype.updateChoices.wrap( function(originalCall, choices){ // do what you need to do before the call originalCall(choices); // do what you need to after the call }); If your project is large enough, you may want to create a separate JS file for extensions/overrides to make it easier to manage. -justin --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Yeah, that''s it. Thanks for pointing out the function that I had missed. http://prototypejs.org/api/function/wrap On Mar 18, 5:27 pm, "Justin Perkins" <justinperk...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> You should try the wrap function technique... > > Autocompleter.Base.prototype.updateChoices > Autocompleter.Base.prototype.updateChoices.wrap( > function(originalCall, choices){ > // do what you need to do before the call > originalCall(choices); > // do what you need to after the call > > }); > > If your project is large enough, you may want to create a separate JS > file for extensions/overrides to make it easier to manage. > > -justin--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---