In the below code, one behaviours object is shared between all popup objects when what I''d like is for each popup object, and in fact each complexDOM object, to have it''s own behaviours object. If I move this.behaviours = new Behaviours(); to the Popup() function, then each popup object then get''s it''s own Behaviours object as I''d like. However, I need to declare it in complexDOM, since all complexDOM''s will have behaviours. Can anyone tell me why this is not working as I expect, and what the solution is? function Behaviours () { this.array = new Array(); } Behaviours.prototype.push(el, event, method) = function() { this.array.push({el, event, method}); } function complexDOM () { this.behaviours = new Behaviours(); } function Popup () { this.options... } Popup.prototype = new complexDOM(); I also found that I was unable to use the below - when trying to loop through this in the list function, ''this'' didn''t have an array data structure: function Behaviours () {} Behaviours.prototype = new Array(); Behaviours.prototype.list = function() { this.each(function(behaviour) {...}); } 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 -~----------~----~----~----~------~----~------~--~---
May you need to ''bind''? Behaviours.prototype.list = function() { this.each(function(behaviour) {...}); }.bind(this); Just a quick thought.. On Jan 21, 2008 8:17 PM, iporter <isporter-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > In the below code, one behaviours object is shared between all popup > objects when what I''d like is for each popup object, and in fact each > complexDOM object, to have it''s own behaviours object. > > If I move this.behaviours = new Behaviours(); to the Popup() function, > then each popup object then get''s it''s own Behaviours object as I''d > like. However, I need to declare it in complexDOM, since all > complexDOM''s will have behaviours. Can anyone tell me why this is not > working as I expect, and what the solution is? > > function Behaviours () { > this.array = new Array(); > } > > Behaviours.prototype.push(el, event, method) = function() { > this.array.push({el, event, method}); > } > > function complexDOM () { > this.behaviours = new Behaviours(); > > } > > function Popup () { > this.options... > } > > Popup.prototype = new complexDOM(); > > I also found that I was unable to use the below - when trying to loop > through this in the list function, ''this'' didn''t have an array data > structure: > > function Behaviours () {} > Behaviours.prototype = new Array(); > Behaviours.prototype.list = function() { > this.each(function(behaviour) {...}); > } > > > 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 -~----------~----~----~----~------~----~------~--~---
On Jan 22, 5:17 am, iporter <ispor...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> In the below code, one behaviours object is shared between all popup > objects when what I''d like is for each popup object, and in fact each > complexDOM object, to have it''s own behaviours object.You could do worse that start by reading some of Douglas Crockfords articles: <URL: http://javascript.crockford.com/javascript.html > <URL: http://javascript.crockford.com/inheritance.html > Then try posting to comp.lang.javascript[1] with questions. Once you understand how javascipt inheritance works and how to use it, you can then choose which design patterns and libraries suit a particular task best. Good luck! :-) 1. <URL: http://groups.google.com.au/group/comp.lang.javascript/topics?hl=en>-- Rob --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---