Actually, having the constructor called without your control could be
disastrous if the constructor of your base class doesn't accept the
same arguments as your derived class. Many languages use static
analysis to determine whether you've explicitly called your base
class' constructor, and if not, call the default one for you. That's
probably out of the realm of feasibility for JavaScript - at least
without the help of peering into the AST.
I think you'll just have to live with invoking your base class'
constructor manually. At least you don't have to do all the tedious
typing to make it work...
On Sep 20, 2007, at 7:35 AM, Les Szklanny 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');
>
> >
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Prototype: Core" group.
To post to this group, send email to [email protected]
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
-~----------~----~----~----~------~----~------~--~---