findingsteve-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2007-Feb-22 12:32 UTC
How to try out Class Animal example (Example 4.1) using prototype 1.5? More options
Someone told to try to ask the question here: I tried to copy the example into a html file. And when I run the page, I didn''t see anything. When I put an alert under var Animal = Class.create(); I didn''t see my alert. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Christophe Porteneuve
2007-Feb-22 13:26 UTC
Re: How to try out Class Animal example (Example 4.1) using prototype 1.5? More options
Hey Steve, findingsteve-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org a écrit :> I didn''t see anything. When I put an alert under > var Animal = Class.create(); > I didn''t see my alert.Check your browser for JS errors. It appears the HTML page you copied this into does not load Prototype before running this script. Do you have something like: <script type="text/javascript" src="your/path/to/prototype.js"></script> ...present before the script you''re playing with? If not, then "Class" does not exist, so doing "Class.create" won''t work: you''ll get a JS error. Depending on the browser you''re playing with, such errors are more or less visible. -- Christophe Porteneuve aka TDD tdd-x+CfDp/qHev2eFz/2MeuCQ@public.gmane.org --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
findingsteve-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2007-Feb-22 15:08 UTC
Re: How to try out Class Animal example (Example 4.1) using prototype 1.5? More options
Yes, I have my prototype.js. I didn''t see any error mesg using IE. I will try to see check it out if there is there is any error using Mozila''s Firebug. Thanks. From, Steve --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
findingsteve-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2007-Feb-23 01:48 UTC
Re: How to try out Class Animal example (Example 4.1) using prototype 1.5? More options
Yah, my fault. Indeed I didn''t have my prototype.js. And after I make sure I have my prototype.js, and run it again, I still didn''t see anything and got 1 error in Mozila, saying: sound is not defined How do I go about it now? Below are the whole code: <script> var Animal = Class.create(); Animal.prototype = { initialize: function(name, sound) { this.name = name; this.sound = sound; }, speak: function() { alert(name + " says: " + sound + "!"); } }; var snake = new Animal("Ringneck", "hissssssssss"); snake.speak(); // -> alerts "Ringneck says: hissssssssss!" var Dog = Class.create(); Dog.prototype = Object.extend(new Animal(), { initialize: function(name) { this.name = name; this.sound = "woof"; } }); var fido = new Dog("Fido"); fido.speak(); // -> alerts "Fido says: woof!" </script> --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Ken Snyder
2007-Feb-23 06:04 UTC
Re: How to try out Class Animal example (Example 4.1) using prototype 1.5? More options
findingsteve-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org wrote:> ... > initialize: function(name, sound) { > this.name = name; > this.sound = sound; > }, > speak: function() { > alert(name + " says: " + sound + "!"); > }just a typo. "sound" should be "this.sound" : speak: function() { alert(name + " says: " + this.sound + "!"); } Regards, Ken Snyder --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
findingsteve-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2007-Feb-23 07:54 UTC
Re: How to try out Class Animal example (Example 4.1) using prototype 1.5? More options
Thanks. I saw the result now after this changes. I realize that name also need to change to this.name. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
kerdosa
2007-Mar-12 04:47 UTC
Re: How to try out Class Animal example (Example 4.1) using prototype 1.5? More options
There is one problem in this approach. In Animal, name and sound are the named properties which is not part of Animal.prototype, but they becomes prototype properties in Dog class, so if you create many different dogs from Dog class, all dogs will share the one name and sound properties, which means if you change the name in one dog, then all the other dogs will get the same name. The prototype Object.extend is mainly for extending property and not good for implementing inheritance. On Feb 23, 1:54 am, "findingst...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org" <findingst...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Thanks. I saw the result now after this changes. I realize that name > also need to change to this.name.--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Christophe Porteneuve
2007-Mar-12 08:23 UTC
Re: How to try out Class Animal example (Example 4.1) using prototype 1.5? More options
Kerdosa, STOP spewing out fallacies about how prototype works. Read my reply to your previous post, then read again how prototype actually works (e.g. on DevMo, or in the ECMA-262 spec), then we''ll welcome your replies once they''re, er... correct. -- Christophe Porteneuve a.k.a. TDD "[They] did not know it was impossible, so they did it." --Mark Twain Email: tdd-x+CfDp/qHev2eFz/2MeuCQ@public.gmane.org --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---