The missing 'this' is just my typo :)

I see your point about being able to control if and how the superclass
constructor is called.
Interestingly, the Dojo team apparently believes that eliminating this
control reduces the size of boilerplate, see this:

http://dojotoolkit.org/book/dojo-book-0-9/part-3-programmatic-dijit-and-dojo/object-orientation/inheritance

On Sep 20, 10:44 am, "Ryan Gahl" <[EMAIL PROTECTED]> wrote:
> 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
> blog:http://www.someelement.com/2007/03/multiple-inheritance-with-prototyp...
>
> 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, LLChttp://www.nthpenguin.com
> --
> Architect
> 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 
http://groups.google.com/group/prototype-core?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to