I consider it bad form to bind to an anonymous function, it works and
it gets the job done, but i think its semantically hideous and also
impairs performance.
I've seen this a lot on ajax response handlers and event handlers,
people will bind a method and send it to the function on the spot.
This has a serious draw back for event handlers, you can't remove
them! Think about it you need the exact reference of what you sent it,
which is now a function closure that you don't have a reference to.
The draw back for ajax requests is that it must bind it everytime the
request is sent. Instead create the closure ahead of time and have it
ready whenever you need it.
A common thing for me to use for a click handle...
this.clickHandle = this.handleClick.bind(this);
On Jul 26, 2:15 pm, Tom Gregory <[EMAIL PROTECTED]> wrote:
> <chuckle> Yeah, the semicolon would get you in trouble there.
>
> Glad you got it working.
>
> TAG
>
> On Jul 26, 2007, at 11:51 AM, gmacgregor wrote:
>
> > On Jul 26, 12:40 pm, David Dashifen Kees <[EMAIL PROTECTED]> wrote:
> >> Tom Gregory wrote:
> >>> Try
> >>> onSuccess: function (t) { /* ... */ }.bind(this)
>
> > Bah!! I tried all sorts of variations with bind(). For example:
>
> > recommend : function() {
> > var url = this.recommend_button.href;
> > new Ajax.Request(url, {
> > method: 'get',
> > onSuccess: function(transport) {
> > //...
> > }.bind(this);
> > });
> > return false;
> > },
>
> > ^^ that implementation threw an error in Firefox. After removing the ;
> > after bind() everything works fine. Thanks for the help!
>
> > Greg
--~--~---------~--~----~------------~-------~--~----~
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 [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/rubyonrails-spinoffs?hl=en
-~----------~----~----~----~------~----~------~--~---