hay / stapes

the Javascript MVC microframework that does just enough
http://hay.github.io/stapes
MIT License
443 stars 54 forks source link

Subclass does not copy extend static methods #61

Closed foxx closed 9 years ago

foxx commented 9 years ago

It would seem that if you extend a class then subclass it, the static method which you added with extend do not appear;

    var cls = Stapes.subclass({

    });

    cls.extend({
      hello: function() {
        return 'world';
      }
    });

    var cls2 = cls.subclass({

    })

    var a = cls2();
    console.log(a.hello());
     TypeError: Object function constructor() {
                // Be kind to people forgetting new
                if (!(this instanceof constructor)) {
                    throw new Error("Please use 'new' when initializing Stapes classes");
                }

                // If this class has events add a GUID as well
                if (this.on) {
                    _.addGuid( this, true );
                }

                realConstructor.apply(this, arguments);
            } has no method 'hello'
foxx commented 9 years ago

Think I've managed to fix this, just finishing up the unit tests, PR coming shortly

hay commented 9 years ago

Thanks for the PR and bug, but this is intended behaviour. Static methods / properties should only appear on the instance, not on every child. If you want that, you should use proto instead of extend.