Any ideas why I only get "klass()" returned when I try to access ClassName.superclass or ClassName.subclasses, and "undefined" when I access class_instant.superclass or class_instant.subclasses? I''m probably doing something really stupid. var Animal = Class.create({ initialize: function(name) { this.name = name; } }); var Dog = Class.create(Animal, { initialize: function($super, name) { $super(name); }, bark: function() { return this.name + '' said "Woof!"''; } }); var poodle = new Dog(''Jack''); poodle.superclass; //--> undefined Dog.superclass; //--> klass() --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Nicolás Sanguinetti
2007-Nov-19 14:05 UTC
Re: 1.6 -- Can''t access superclass or subclasses
You have to call it on the Class, not the instances, and the "klass()" returned works fine. With your example: var duck = new (Dog.superclass)("ducky"); duck instanceof Animal>>> trueBest, -Nicolas On Nov 19, 2007 11:59 AM, redheat <ecouchman-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote:> > Any ideas why I only get "klass()" returned when I try to access > ClassName.superclass or ClassName.subclasses, and "undefined" when I > access class_instant.superclass or class_instant.subclasses? > > I''m probably doing something really stupid. > > var Animal = Class.create({ > initialize: function(name) { > this.name = name; > } > }); > > var Dog = Class.create(Animal, { > initialize: function($super, name) { > $super(name); > }, > > bark: function() { > return this.name + '' said "Woof!"''; > } > }); > > var poodle = new Dog(''Jack''); > poodle.superclass; //--> undefined > Dog.superclass; //--> klass() > > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Okay... how do I get the name of the superclass from within the class? For example: how can I tell from within the Dog Class that Dog is a subclass of Animal. How can I get the name "Animal" without using instanceof? Edd On Nov 19, 2:05 pm, "Nicolás Sanguinetti" <godf...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> You have to call it on the Class, not the instances, and the "klass()" > returned works fine. With your example: > > var duck = new (Dog.superclass)("ducky"); > duck instanceof Animal > > >>> true > > Best, > -Nicolas > > On Nov 19, 2007 11:59 AM, redheat <ecouch...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote: > > > > > Any ideas why I only get "klass()" returned when I try to access > > ClassName.superclass or ClassName.subclasses, and "undefined" when I > > access class_instant.superclass or class_instant.subclasses? > > > I''m probably doing something really stupid. > > > var Animal = Class.create({ > > initialize: function(name) { > > this.name = name; > > } > > }); > > > var Dog = Class.create(Animal, { > > initialize: function($super, name) { > > $super(name); > > }, > > > bark: function() { > > return this.name + '' said "Woof!"''; > > } > > }); > > > var poodle = new Dog(''Jack''); > > poodle.superclass; //--> undefined > > Dog.superclass; //--> klass()--~--~---------~--~----~------------~-------~--~----~ 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... can''t. That''s a limitations of JavaScript. On Nov 19, 6:45 pm, redheat <ecouch...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote:> Okay... how do I get the name of the superclass from within the class? > For example: how can I tell from within the Dog Class that Dog is a > subclass of Animal. How can I get the name "Animal" without using > instanceof? > > Edd > > On Nov 19, 2:05 pm, "Nicolás Sanguinetti" <godf...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> You have to call it on the Class, not the instances, and the "klass()" > > returned works fine. With your example: > > > var duck = new (Dog.superclass)("ducky"); > > duck instanceof Animal > > > >>> true > > > Best, > > -Nicolas > > > On Nov 19, 2007 11:59 AM, redheat <ecouch...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote: > > > > Any ideas why I only get "klass()" returned when I try to access > > > ClassName.superclass or ClassName.subclasses, and "undefined" when I > > > access class_instant.superclass or class_instant.subclasses? > > > > I''m probably doing something really stupid. > > > > var Animal = Class.create({ > > > initialize: function(name) { > > > this.name = name; > > > } > > > }); > > > > var Dog = Class.create(Animal, { > > > initialize: function($super, name) { > > > $super(name); > > > }, > > > > bark: function() { > > > return this.name + '' said "Woof!"''; > > > } > > > }); > > > > var poodle = new Dog(''Jack''); > > > poodle.superclass; //--> undefined > > > Dog.superclass; //--> klass()--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---