Greetings,
I had a question about the $super argument that I wasn''t
able to find in documentation, searching etc. What exactly is the
$super argument. Is it a reference to the super class''s prototype
function? Or is it an instantiated object of the super class that is
passed to the subclass''s method?
I am completely confuzzled on this one, my typical method of just
reading the source has left me worse off. Can anyone explain this
concept or perhaps point me to a resource which properly defines it?
Thanks in advance,
Matt
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---
$super is a reference to the current function in the superclass. So,
Animal = Class.create({
initialize: function(legs) {
this.legs = legs;
}
});
Dog = Class.create(Animal, {
initialize: function($super, legs, name) {
$super(legs);
this.name = name;
}
});
new Dog(4, "Zombie")
Best,
-Nicolas
On Dec 20, 2007 5:27 PM, Matt Foster
<mattfoster01-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
wrote:>
> Greetings,
>
> I had a question about the $super argument that I wasn''t
> able to find in documentation, searching etc. What exactly is the
> $super argument. Is it a reference to the super class''s prototype
> function? Or is it an instantiated object of the super class that is
> passed to the subclass''s method?
>
> I am completely confuzzled on this one, my typical method of just
> reading the source has left me worse off. Can anyone explain this
> concept or perhaps point me to a resource which properly defines it?
>
> Thanks in advance,
> Matt
> >
>
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---
From a non-Ruby guy, here is the scoop:
Ruby has a keyword "super" that is available within all methods. It
allows you to call the parent function of the same name.
In php I write:
public function mymethod($arg) {
parent::mymethod($arg); // equivalent to Ruby super($arg)
}
So this JS implementation basically has $super refer to the parent
method of the same name so you can call $super()
"$super" is used instead of "super" because
"super" is a reserved word
in JS.
The sugar is that extended classes automagically pass a reference of the
parent function into child function only for methods that have a $super
argument (detected when the child function is converted to a string with
toString()).
- Ken Snyder
PS. great interjection of "confuzzled"!
Matt Foster wrote:> Greetings,
>
> I had a question about the $super argument that I wasn''t
> able to find in documentation, searching etc. What exactly is the
> $super argument. Is it a reference to the super class''s prototype
> function? Or is it an instantiated object of the super class that is
> passed to the subclass''s method?
>
> I am completely confuzzled on this one, my typical method of just
> reading the source has left me worse off. Can anyone explain this
> concept or perhaps point me to a resource which properly defines it?
>
> Thanks in advance,
> Matt
>
--~--~---------~--~----~------------~-------~--~----~
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 for the win! That is what i have been looking for, the non- Ruby scoop. On Dec 20, 2:38 pm, Ken Snyder <kendsny...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> From a non-Ruby guy, here is the scoop: > > Ruby has a keyword "super" that is available within all methods. It > allows you to call the parent function of the same name. > > In php I write: > public function mymethod($arg) { > parent::mymethod($arg); // equivalent to Ruby super($arg) > > } > > So this JS implementation basically has $super refer to the parent > method of the same name so you can call $super() > > "$super" is used instead of "super" because "super" is a reserved word > in JS. > > The sugar is that extended classes automagically pass a reference of the > parent function into child function only for methods that have a $super > argument (detected when the child function is converted to a string with > toString()). > > - Ken Snyder > > PS. great interjection of "confuzzled"! > > Matt Foster wrote: > > Greetings, > > > I had a question about the $super argument that I wasn''t > > able to find in documentation, searching etc. What exactly is the > > $super argument. Is it a reference to the super class''s prototype > > function? Or is it an instantiated object of the super class that is > > passed to the subclass''s method? > > > I am completely confuzzled on this one, my typical method of just > > reading the source has left me worse off. Can anyone explain this > > concept or perhaps point me to a resource which properly defines it? > > > Thanks in advance, > > Matt--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---