quick and dirty solution is:
$('someElement').observe('keyup', this.handler.bindAsEventListener(this));
Note both that you have to say "this.handler"... and you also have to do
".bindAsEventListener(this)". .bind(this) would work also if the handler
wasn't expecting the event object to be passed in, but as it is you need the
former.
Long term better way to do class creation and have truly instance only
members (and true private/public accessors) though, is to encapsulate
everything that's supposed to be instance only inside the constructor. This
goes a bit against the grain as far as what most prototype users are
accustomed to though. You can read more in my blog ( www.someElement.com)...
The post about multiple inheritance is the one where I explain this a bit.
The way you have written this is what I call "prototype static". While you
can say "well I just wouldn't do this".. it's entirely possibly to later
write the static line " a.prototype.handler(something)"... which would cause
errors.
I know... a lot of people will argue that my flavor of encapsulation isn't
truly necessary, but that's my opinion anyway, take it for what it's worth
:) I prefer true access level definitions on class members vs. pseudo.
On 11/21/07, xzyfer <[EMAIL PROTECTED] > wrote:
>
>
> 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!
> >
>
--
Ryan Gahl
Manager, Senior Software Engineer
Nth Penguin, LLC
http://www.nthpenguin.com
--
Architect
WebWidgetry.com / MashupStudio.com
Future Home of the World's First Complete Web Platform
--
Inquire: 1-262-951-6727
Blog: http://www.someElement.com
LinkedIn Profile: http://www.linkedin.com/in/ryangahl
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---