turing.js icon indicating copy to clipboard operation
turing.js copied to clipboard

It seems that turing.oo.js don't support for multi inheritance??

Open imnemo opened this issue 12 years ago • 0 comments

var User = turing.Class({ 'initialize' : function(name, age){ console.log('User init!'); this.name = name; this.age = age; }, 'toString' : function(){ var str = ''; for(var key in this){ if(typeof this[key] !== 'function' && key !== '$parent'){ str += key + " : " + this[key] + "\n"; } } return str; } }); var superUser = turing.Class(User, { 'initialize' : function(){ console.log('superUser init!'); this.$super('initialize', arguments); this.sex = arguments[2]; }, 'toString' : function(){ return "Overwrite the parent method : \n" + this.$super('toString'); } });

var superSuperUser = turing.Class(superUser, { 'initialize' : function(){ console.log('superSuperUser init!'); this.$super('initialize', arguments); this.love = arguments[3]; }, 'toString' : function(){ return "Overwrite the parent method : \n" + this.$super('toString'); } });

As shown above, superUser inherits from User and superSuperUser attempts to inherit from superUser. However, when the superSuperUser is initialized, a infinit circle happens in superUser's 'initialize' method. It seems that in superUser's 'initialize' method, "this" also points to superSuperUser, but not superUser, which case cause the infinit circle.

I just don't know if I understand something wrong, thanks anyone who can help me!

imnemo avatar Apr 26 '12 13:04 imnemo