Hi,
I have a class with DOM elements as properties. I want to bind events
within the class to the ements. Unfortunately I am getting an error
telling me those properties are not defined. Here''s an simplfied
example of what I''m trying to achieve.
var MyClass=Class.create()
MyClass.prototye = {
initialize: function(element1, element2){
this.element1=element1;
this.element2=element2;
this.element1.observe(''click'',this.hide);
},
hide: function(){
this.element2.hide();
}
Thanks for your help
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---
hide method needs to be bound to an instance of your class when using
it as an event handler.
...
this.element1.observe(''click'', this.hide.bind(this));
...
- kangax
On Feb 14, 12:27 pm, kojilab
<koji...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
wrote:> Hi,
>
> I have a class with DOM elements as properties. I want to bind events
> within the class to the ements. Unfortunately I am getting an error
> telling me those properties are not defined. Here''s an simplfied
> example of what I''m trying to achieve.
>
> var MyClass=Class.create()
> MyClass.prototye = {
> initialize: function(element1, element2){
> this.element1=element1;
> this.element2=element2;
> this.element1.observe(''click'',this.hide);
> },
>
> hide: function(){
> this.element2.hide();
> }
>
> Thanks for your help
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---
Thanks a lot On Feb 14, 10:37 am, kangax <kan...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> hide method needs to be bound to an instance of your class when using > it as an event handler. > > ... > this.element1.observe(''click'', this.hide.bind(this)); > ... > > - kangax > > On Feb 14, 12:27 pm, kojilab <koji...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > Hi, > > > I have a class with DOM elements as properties. I want to bind events > > within the class to the ements. Unfortunately I am getting an error > > telling me those properties are not defined. Here''s an simplfied > > example of what I''m trying to achieve. > > > var MyClass=Class.create() > > MyClass.prototye = { > > initialize: function(element1, element2){ > > this.element1=element1; > > this.element2=element2; > > this.element1.observe(''click'',this.hide); > > }, > > > hide: function(){ > > this.element2.hide(); > > } > > > Thanks for your help--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Actually the bind throws an error in Firebug this.hide has no properties On Feb 14, 10:37 am, kangax <kan...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> hide method needs to be bound to an instance of your class when using > it as an event handler. > > ... > this.element1.observe(''click'', this.hide.bind(this)); > ... > > - kangax > > On Feb 14, 12:27 pm, kojilab <koji...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > Hi, > > > I have a class with DOM elements as properties. I want to bind events > > within the class to the ements. Unfortunately I am getting an error > > telling me those properties are not defined. Here''s an simplfied > > example of what I''m trying to achieve. > > > var MyClass=Class.create() > > MyClass.prototye = { > > initialize: function(element1, element2){ > > this.element1=element1; > > this.element2=element2; > > this.element1.observe(''click'',this.hide); > > }, > > > hide: function(){ > > this.element2.hide(); > > } > > > Thanks for your help--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Please give us a URL so that we can see what you''ve done. That way it''ll be much easier to help. Cheers, Andrew On Feb 14, 3:20 pm, kojilab <koji...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Actually the bind throws an error in Firebug > this.hide has no properties > > On Feb 14, 10:37 am, kangax <kan...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > hide method needs to be bound to an instance of your class when using > > it as an event handler. > > > ... > > this.element1.observe(''click'', this.hide.bind(this)); > > ... > > > - kangax > > > On Feb 14, 12:27 pm, kojilab <koji...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > Hi, > > > > I have a class with DOM elements as properties. I want to bind events > > > within the class to the ements. Unfortunately I am getting an error > > > telling me those properties are not defined. Here''s an simplfied > > > example of what I''m trying to achieve. > > > > var MyClass=Class.create() > > > MyClass.prototye = { > > > initialize: function(element1, element2){ > > > this.element1=element1; > > > this.element2=element2; > > > this.element1.observe(''click'',this.hide); > > > }, > > > > hide: function(){ > > > this.element2.hide(); > > > } > > > > Thanks for your help--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
It''s not live and the code is exactly the same as the one posted aside from different variable names. On Feb 14, 1:29 pm, Andrew Dupont <goo...-TiabPMV39B5K4mp1Ns0Z8Q@public.gmane.org> wrote:> Please give us a URL so that we can see what you''ve done. That way > it''ll be much easier to help. > > Cheers, > Andrew > > On Feb 14, 3:20 pm, kojilab <koji...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > Actually the bind throws an error in Firebug > > this.hide has no properties > > > On Feb 14, 10:37 am, kangax <kan...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > hide method needs to be bound to an instance of your class when using > > > it as an event handler. > > > > ... > > > this.element1.observe(''click'', this.hide.bind(this)); > > > ... > > > > - kangax > > > > On Feb 14, 12:27 pm, kojilab <koji...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > Hi, > > > > > I have a class with DOM elements as properties. I want to bind events > > > > within the class to the ements. Unfortunately I am getting an error > > > > telling me those properties are not defined. Here''s an simplfied > > > > example of what I''m trying to achieve. > > > > > var MyClass=Class.create() > > > > MyClass.prototye = { > > > > initialize: function(element1, element2){ > > > > this.element1=element1; > > > > this.element2=element2; > > > > this.element1.observe(''click'',this.hide); > > > > }, > > > > > hide: function(){ > > > > this.element2.hide(); > > > > } > > > > > Thanks for your help--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
I am an idiot. I had renamed my method and forgot to update it. On Feb 14, 1:29 pm, Andrew Dupont <goo...-TiabPMV39B5K4mp1Ns0Z8Q@public.gmane.org> wrote:> Please give us a URL so that we can see what you''ve done. That way > it''ll be much easier to help. > > Cheers, > Andrew > > On Feb 14, 3:20 pm, kojilab <koji...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > Actually the bind throws an error in Firebug > > this.hide has no properties > > > On Feb 14, 10:37 am, kangax <kan...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > hide method needs to be bound to an instance of your class when using > > > it as an event handler. > > > > ... > > > this.element1.observe(''click'', this.hide.bind(this)); > > > ... > > > > - kangax > > > > On Feb 14, 12:27 pm, kojilab <koji...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > Hi, > > > > > I have a class with DOM elements as properties. I want to bind events > > > > within the class to the ements. Unfortunately I am getting an error > > > > telling me those properties are not defined. Here''s an simplfied > > > > example of what I''m trying to achieve. > > > > > var MyClass=Class.create() > > > > MyClass.prototye = { > > > > initialize: function(element1, element2){ > > > > this.element1=element1; > > > > this.element2=element2; > > > > this.element1.observe(''click'',this.hide); > > > > }, > > > > > hide: function(){ > > > > this.element2.hide(); > > > > } > > > > > Thanks for your help--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---