Hi Prototype User Group! I''m having a bit of trouble. I''m trying to call methods: create and destroy but they don''t work. "this.destroy is not a function" I think I''m missing a step here. var Ball = { b_appear: false, appear: function() { if (this.b_appear) { this.create(); this.b_appear = false; } else { this.destroy(); this.b_reorder = true; } }, create: function() { alert(''create'') }, destroy: function() { alert(''destroy'') } } document.observe(''dom:loaded'', function() { $(''ball'').observe( ''click'', Ball.appear); }); Any ideas? --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
You need to bind the "this" object to your Ball object for the event listener. Also, instead of using anonymous functions as page initializers, I prefer to utilize named methods (so they can be more easily extended/detached). var Ball = { initialize: function(){ this.ball = $(''ball''); this.ball.observe(''click'', this.appear.bindAsEventListener(this)); }, appear: function(event){ if (this.ballAppeared) this.destroy(); else this.create(); }, create: function(){ this.ballAppeared = true; alert("Creating my ball from: " + this.ball); }, destroy: function(){ this.ballAppeared = false; alert("Destroying my ball from: " + this.ball); } }; document.observe(''dom:loaded'', Ball.initialize.bindAsEventListener(Ball)); Have a great day. -justin --~--~---------~--~----~------------~-------~--~----~ 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 for the help! On Jan 29, 4:15 pm, "Justin Perkins" <justinperk...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> You need to bind the "this" object to your Ball object for the event > listener. Also, instead of using anonymous functions as page > initializers, I prefer to utilize named methods (so they can be more > easily extended/detached). > > var Ball = { > initialize: function(){ > this.ball = $(''ball''); > this.ball.observe(''click'', this.appear.bindAsEventListener(this)); > }, > appear: function(event){ > if (this.ballAppeared) > this.destroy(); > else > this.create(); > }, > create: function(){ > this.ballAppeared = true; > alert("Creating my ball from: " + this.ball); > }, > destroy: function(){ > this.ballAppeared = false; > alert("Destroying my ball from: " + this.ball); > }}; > > document.observe(''dom:loaded'', Ball.initialize.bindAsEventListener(Ball)); > > Have a great day. > > -justin--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---