tnhu / jsface

Small, fast, elegant, powerful, and cross platform JavaScript OOP library. Support main(), singleton, super call, private, mixins, plugins, AOP and more.
MIT License
301 stars 46 forks source link

Super's constructor not getting called if sub class not defining constructor #13

Closed alyph closed 11 years ago

alyph commented 11 years ago

When no constructor defined, an empty function is created instead, which however does not call super constructor. Expected behavior is if sub class has no constructor it automatically calls super class one.

Suggested fix:

// construct constructor
clazz  = singleton ? {} : (constructor ? (overload ? overload("constructor", constructor) : constructor) : 
  (isClass(parent) ? function(){ parent.apply(this, arguments); } : function(){}));

A better way may be using the p found in later code, which require rearrange the code a little bit

tnhu commented 11 years ago

Thanks alyph!

Calling parent's constructor automatically may cause a lot of surprising issues. I would rather let sub-classes choose than forcing them to employ their parents' constructor.