Except i believe you really want call() here and not apply(), as you are not
giving the base constructor the instance reference being acted upon. If
"this" is used within the base class constructor, you'd run into problems.
In your case what you want is something like
Animal.prototype.initialize.call(this, name). Also, in some cases it is
desirable to have control over when (and if) the base class methods get
called. For instance, if you first did some validation of data types of the
supplied arguments, or some other setup steps that are needed in the
subclass before constructing from the base class...

There are several models available to skin the inheritance 'cat' in
javascript. Obviously, you can still choose to roll your own as you see fit.
Proto is a baseline... repeat after me :)

For another inheritance model that supports multiple inheritance see my

On 9/20/07, Les Szklanny <[EMAIL PROTECTED]> wrote:
> Oh boy... what happened to the principle of least surprise? :)
> I can invoke the superclass constructor by adding this line:
> Animal.prototype.initialize.apply(arguments);
> But, shouldn't have to do this or use $super(name).  The superclass
> constructor should be called automatically (as in Dojo for example).
> See the complete code below:
> var Animal = Class.create({
>  initialize: function(name) {
>    alert('Animal: initialize');
>    this.name = name;
>  },
> });
> // subclass that augments a method
> var Cat = Class.create(Animal, {
>  initialize: function(name) {
>    Animal.prototype.initialize.apply(arguments);
>     alert('Cat : initialize');
>  },
> });
> var cat = new Cat('test');
> >

Ryan Gahl
Manager, Senior Software Engineer
Nth Penguin, LLC
WebWidgetry.com / MashupStudio.com
Future Home of the World's First Complete Web Platform
Inquire: 1-262-951-6727
Blog: http://www.someElement.com
LinkedIn Profile: http://www.linkedin.com/in/ryangahl

You received this message because you are subscribed to the Google Groups 
"Prototype: Core" group.
To post to this group, send email to prototype-core@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 

Reply via email to