Jquery also references "this" inside the function as the object / element clicked..

Alex Mcauley
http://www.thevacancymarket.com
----- Original Message ----- From: "Walter Lee Davis" <[email protected]>
To: <[email protected]>
Sent: Monday, May 10, 2010 3:55 PM
Subject: Re: [Proto-Scripty] Binding functions to $$ directly


jQuery conflates the meaning of $ and $$ in a useful manner, but Prototype provides the invoke function to shortcut what you are doing here.

$$('#div1 p span.someclassName').invoke('observe','click', function(el)
{
   alert('b');
});

To my mind, it's a little less magic and a lot more intentional. Note also in this case that where you have el, the reference is really to the click event, so I would write this as function(evt) just to note that. Prototype also scopes 'this' inside of your looped function, so if you wanted to alert(this), you would get the individual span element as your value.

Walter

On May 10, 2010, at 10:43 AM, Phonethics wrote:

How come I got to this

$$('#div1 p span.someclassName').each(function(el)
{
   Event.observe(el, 'click', function(event)
   {
       alert('a');
   });
});

instead of something like this ?

$$('#div1 p span.someclassName').observe('click', function(el)
{
   alert('b');
});

Any way to get the latter to work like in jQuery ?

--
You received this message because you are subscribed to the Google Groups "Prototype & script.aculo.us" 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/prototype-scriptaculous?hl=en .


--
You received this message because you are subscribed to the Google Groups "Prototype & script.aculo.us" 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/prototype-scriptaculous?hl=en.



--
You received this message because you are subscribed to the Google Groups "Prototype 
& script.aculo.us" 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/prototype-scriptaculous?hl=en.

Reply via email to