I have the class below. Trying to do a simple rollover class. var Rollover = Class.create(); Rollover.prototype = { initialize: function(className) { $$(className).each(function(x) { x.mouseover = this.doHover.bindAsEventListener(this); }); }, doHover: function(e) { alert("over"); } }; It errors on the line (x.mouseover this.doHover.bindAsEventListener(this);) with the following message: this.doHover has no properties Any ideas why? I''ve used the bindAseventListener before, and haven''t seen this error. Its probably something painfully obvious that I''m missing or forgetting... Thanks --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
In the line: x.mouseover = this.doHover.bindAsEventListener(this) this doesn''t refer to what you''re thinking. It''s inside the closure, which changes the scope chain. Rollover.prototype = { initialize: function(className) { var doHover = this.doHover.bindAsEventListener(this); $$(className).each(function(x) { x.mouseover = doHover; }); }, doHover: function(e) { alert("over"); } }; Will do what you''re looking to do. On 11/9/06, Bryce Fischer <bryce-bKrBQupY3dcvEkJ3hUJ36NBPR1lH4CV8@public.gmane.org> wrote:> > > I have the class below. Trying to do a simple rollover class. > > var Rollover = Class.create(); > > Rollover.prototype = { > initialize: function(className) { > $$(className).each(function(x) { > x.mouseover = this.doHover.bindAsEventListener > (this); > }); > }, > doHover: function(e) { > alert("over"); > } > }; > > It errors on the line (x.mouseover > this.doHover.bindAsEventListener(this);) with the following message: > this.doHover has no properties > > Any ideas why? I''ve used the bindAseventListener before, and haven''t > seen this error. Its probably something painfully obvious that I''m > missing or forgetting... > > Thanks > > > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Rollover.prototype = { initialize: function(className) { $$(className).each(function(x) { x.mouseover = this.doHover.bindAsEventListener (this); }.bind(this)); }, doHover: function(e) { alert("over"); } }; just another way ;) brgds, sigi On 11/9/06, Jay Miller <heinousjay-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > In the line: > x.mouseover = this.doHover.bindAsEventListener(this) > this doesn''t refer to what you''re thinking. It''s inside the closure, > which changes the scope chain. > > Rollover.prototype = { > initialize: function(className) { > var doHover = this.doHover.bindAsEventListener(this); > $$(className).each(function(x) { > x.mouseover = doHover; > }); > }, > doHover: function(e) { > alert("over"); > } > }; > > Will do what you''re looking to do. > > On 11/9/06, Bryce Fischer < bryce-bKrBQupY3dcvEkJ3hUJ36NBPR1lH4CV8@public.gmane.org> wrote: > > > > > > I have the class below. Trying to do a simple rollover class. > > > > var Rollover = Class.create(); > > > > Rollover.prototype = { > > initialize: function(className) { > > $$(className).each(function(x) { > > x.mouseover = this.doHover.bindAsEventListener(this); > > }); > > }, > > doHover: function(e) { > > alert("over"); > > } > > }; > > > > It errors on the line (x.mouseover > > this.doHover.bindAsEventListener (this);) with the following message: > > this.doHover has no properties > > > > Any ideas why? I''ve used the bindAseventListener before, and haven''t > > seen this error. Its probably something painfully obvious that I''m > > missing or forgetting... > > > > Thanks > > > > > > > > > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Thank you. That worked. On 11/9/06, Jay Miller <heinousjay-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> In the line: > x.mouseover = this.doHover.bindAsEventListener(this) > > this doesn''t refer to what you''re thinking. It''s inside the closure, which > changes the scope chain. > > Rollover.prototype = { > initialize: function(className) { > var doHover > this.doHover.bindAsEventListener(this); > $$(className).each(function(x) { > x.mouseover = doHover; > }); > }, > doHover: function(e) { > alert("over"); > } > }; > > Will do what you''re looking to do. > > > On 11/9/06, Bryce Fischer < bryce-bKrBQupY3dcvEkJ3hUJ36NBPR1lH4CV8@public.gmane.org> wrote: > > > > > > I have the class below. Trying to do a simple rollover class. > > > > var Rollover = Class.create(); > > > > Rollover.prototype = { > > initialize: function(className) { > > $$(className).each(function(x) { > > x.mouseover > this.doHover.bindAsEventListener (this); > > }); > > }, > > doHover: function(e) { > > alert("over"); > > } > > }; > > > > It errors on the line (x.mouseover > > this.doHover.bindAsEventListener (this);) with the > following message: > > this.doHover has no properties > > > > Any ideas why? I''ve used the bindAseventListener before, and haven''t > > seen this error. Its probably something painfully obvious that I''m > > missing or forgetting... > > > > Thanks > > > > > > > > > > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Jay Miller wrote:> In the line: > x.mouseover = this.doHover.bindAsEventListener(this) > this doesn''t refer to what you''re thinking. It''s inside the closure, which > changes the scope chain.The value of a function''s this keyword is not affected by, nor does it have any effect on, the scope chain. Its value is determined *only* by how the function is called. -- Fred --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
The difference is semantic here. I''m not a language lawyer, nor do I care to be. On 11/9/06, Fred <ozfred-AFFH1GffN5hPR4JQBCEnsQ@public.gmane.org> wrote:> > > > Jay Miller wrote: > > In the line: > > x.mouseover = this.doHover.bindAsEventListener(this) > > this doesn''t refer to what you''re thinking. It''s inside the closure, > which > > changes the scope chain. > > The value of a function''s this keyword is not affected by, nor does it > have any effect on, the scope chain. Its value is determined *only* by > how the function is called. > > > -- > Fred > > > > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---