$$, the each function and binding

0 views
Skip to first unread message

Abbas

unread,
Nov 5, 2009, 5:37:38 AM11/5/09
to Prototype & script.aculo.us
Hi,
I encountered a scenario wherin if i do

$$(some selector).each(function(node){
someFunction(node, this)
}).bind(this)

, the 'this' object within someFunction() is not the original context
that i bound the 'each' function to.

Can you please explain?
Thanks

T.J. Crowder

unread,
Nov 6, 2009, 8:45:26 AM11/6/09
to Prototype & script.aculo.us
Hi,

You're calling #bind on the return value from #each, which is
incorrect -- #each returns the enumerable object, which doesn't have a
#bind method.

What you're looking for is the second _parameter_ to #each, details in
the docs[1].

[1] http://api.prototypejs.org/language/enumerable.html#each-instance_method

HTH,
--
T.J. Crowder
Independent Software Consultant
tj / crowder software / com
www.crowdersoftware.com
Reply all
Reply to author
Forward
0 new messages