How to pass parameters to a function in Event.observe

2 views
Skip to first unread message

nicotux

unread,
Nov 2, 2007, 12:13:17 PM11/2/07
to Ruby on Rails: Spinoffs
Hi,

I would like to know (if it is possible) how to pass parameters to a
function in Event.observe

Example :
Event.observe(tag_id, "change", myfunction, false);

The function myfunction should have a specific behavoir according to
parameters :
function myfunction(param1, param2);

Thank you.

Michael Peters

unread,
Nov 2, 2007, 12:14:51 PM11/2/07
to rubyonrail...@googlegroups.com
nicotux wrote:

This is what a closure is for.

Event.observe(tag_id, "change", function() { myfunction(param1, param2) }, false)


--
Michael Peters
Developer
Plus Three, LP

Trevan Richins

unread,
Nov 2, 2007, 12:34:23 PM11/2/07
to rubyonrail...@googlegroups.com
In 1.6, you could also use the new curry function:

Event.observe(tag_id, 'change', myfunction.curry(param1, param2), false);

nicotux

unread,
Nov 2, 2007, 2:58:49 PM11/2/07
to Ruby on Rails: Spinoffs
Ok, thank you very much !

Richard Quadling

unread,
Nov 5, 2007, 7:15:46 AM11/5/07
to rubyonrail...@googlegroups.com
On 02/11/2007, nicotux <nic...@gmail.com> wrote:
>
> Ok, thank you very much !
>
Ditto.


>
> >
>


--
-----
Richard Quadling
Zend Certified Engineer : http://zend.com/zce.php?c=ZEND002498&r=213474731
"Standing on the shoulders of some very clever giants!"

Reply all
Reply to author
Forward
0 new messages