It seems to me that it's a matter of which element 'this' refers to.
In this case, when the 'keyup' fires, 'this' will refer to $
('some_element'), not to the element you probably expected.
Take a look at http://www.prototypejs.org/api/function
and try this:
$('some_element').observe('keyup', this.handler.bind(this));
If anyone has a more elegant way to solve this, please let me know.
Fabio
xzyfer escreveu:
> hey all,
>
> im having a problem:
>
> var a = Class.create({
>
> initialize: function(s) {
> this.s = s;
> $('some_element').observe('keyup',handler);
> },
>
> handler: function(event)
> {
> console.log(this.s);
> }
>
> });
>
> this is just a quick example of the problem, not the actual code im
> using.
>
> for some reason, the reference to this.s, is not being passed to
> handler().
> i get console output "undefined", iv done alot of OOP in my time, and
> i cant see why this isnt working,
>
> any help would be great!
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---