albertpare-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2007-Oct-19 14:02 UTC
help please, problem with Event.observe, into declaration CLASS
hi boys;
i have a problem with Event.observe .
i want to assing onclick event into a declaration object.
something like :
======================================================miG = Class.create();
miG.prototype = {
// ........................................
initialize: function( oneElement )
{
Event.observe( oneElement , ''click'', this.one_method )
<-----
problem at runtime, this is loss
} ,
// ........................................
one_method: function (e) {
do something ...... .. . . ..
}
} // end class
o_miG=new miG( $(''oneDiv'') );
======================================================
the problem is the "THIS" object i loss at runtime , any idea ?
thks, all.
regards form spain.
albert.
--~--~---------~--~----~------------~-------~--~----~
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
rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-spinoffs?hl=en
-~----------~----~----~----~------~----~------~--~---
Bart Lewis
2007-Oct-19 15:02 UTC
Re: help please, problem with Event.observe, into declaration CLASS
You need a bind.
Event.observe(oneElement , ''click'', function(){
this.one_method()
}.bind(this));
-B
On Oct 19, 7:02 am,
"albertp...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org"
<albertp...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
wrote:> hi boys;
>
> i have a problem with Event.observe .
> i want to assing onclick event into a declaration object.
> something like :
> ======================================================> miG =
Class.create();
> miG.prototype = {
> // ........................................
> initialize: function( oneElement )
> {
> Event.observe( oneElement , ''click'',
this.one_method ) <-----
> problem at runtime, this is loss
> } ,
> // ........................................
> one_method: function (e) {
> do something ...... .. . . ..
> }
>
> } // end class
>
> o_miG=new miG( $(''oneDiv'') );
> ======================================================>
> the problem is the "THIS" object i loss at runtime , any idea ?
>
> thks, all.
>
> regards form spain.
> albert.
--~--~---------~--~----~------------~-------~--~----~
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
rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-spinoffs?hl=en
-~----------~----~----~----~------~----~------~--~---
Trevan Richins
2007-Oct-19 15:43 UTC
Re: help please, problem with Event.observe, into declaration CLASS
You could also write it as: Event.observe(oneElement , ''click'', this.one_method.bind(this)); Trevan Bart Lewis wrote:> You need a bind. > > Event.observe(oneElement , ''click'', function(){ > this.one_method() > }.bind(this)); > > -B > > On Oct 19, 7:02 am, "albertp...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org" <albertp...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > wrote: > >> hi boys; >> >> i have a problem with Event.observe . >> i want to assing onclick event into a declaration object. >> something like : >> ======================================================>> miG = Class.create(); >> miG.prototype = { >> // ........................................ >> initialize: function( oneElement ) >> { >> Event.observe( oneElement , ''click'', this.one_method ) <----- >> problem at runtime, this is loss >> } , >> // ........................................ >> one_method: function (e) { >> do something ...... .. . . .. >> } >> >> } // end class >> >> o_miG=new miG( $(''oneDiv'') ); >> ======================================================>> >> the problem is the "THIS" object i loss at runtime , any idea ? >> >> thks, all. >> >> regards form spain. >> albert. >> > > > > >--~--~---------~--~----~------------~-------~--~----~ 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 rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---