ded / klass

a utility for creating expressive classes in JavaScript
753 stars 78 forks source link

initialize() being applied to all klass() Objects after an .extend() #7

Closed stephenmelrose closed 13 years ago

stephenmelrose commented 13 years ago

I came across the following scenario this evening,

var MyTest1 = klass({
    initialize: function() {
        console.log('MyTest1 Constructor');
    }
});

var MyTest1Child = MyTest1.extend({});

var MyTest2 = klass({});

var instance = new MyTest2();

In the example above, the constructor on MyTest1 is being executed when instantiating MyTest2.

I would not expect this as MyTest2 doesn't have a constructor, nor does it extend anything.

This appears to happen to all subsequent objects declared after the first .extend() is made, and the constructor called is the constructor of the object being extended.

Note, this does not happen if declare a constructor on the extended object.

ded commented 13 years ago

looking at this now

stephenmelrose commented 13 years ago

Cheers me dears!