This repository has been archived by the owner on Dec 4, 2023. It is now read-only.
Need a way to pass this
context to JS functions implemented in Ruby
#105
Labels
raised by cowboyd/handlebars.rb#4
suppose we have the following code:
there is no way for the lambda bound to
fn
to access the value ofthis
in the context of the JavaScript call; in this case, the string "foo". We need a way to be able to do this.Ways to do this:
(A) Pass it in as the first argument to the proc.
This would basically break every library that uses TRR, but it is obvious what's happening. When you bind an anonymous Ruby function to a JavaScript function, you always get
this
as the first argument.(B) Rebind self in the context of the received object
This might break less code, although it would still break some. Worse, it will probably do so in strange ways. On the other hand, it is more true to the way JavaScript is --constantly keeping you on your toes about what the context is.
In either case, it should be possible to implement these two different strategies in the different contexts.
The text was updated successfully, but these errors were encountered: