Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
imnemo opened this issue Apr 26, 2012 · 0 comments
Open

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

imnemo opened this issue Apr 26, 2012 · 0 comments

Comments

@imnemo
Copy link

imnemo commented Apr 26, 2012

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant