Conversation
|
This is a big change set. Thank you for going through all that ~ and making sure the tests pass :). The only change I'm really not comfortable with is item 3, "Remove I used where or By using or I don't have to pass Would it be possible to update the pull request so as to support the |
|
Thanks for reviewing. I can understand your requirement about var Animal = Constructor({
constructor: function(name) {
this.name = name;
},
shout: function (str) {
alert(this.name + str);
}
});
var Dog = Constructor({
constructor: function(name) {
this.__super__(name); // Dog.prototype.__super__ = Animal
},
shout: function () {
alert('wow~');
}
}, Animal);
var Husky = Constructor({
constructor: function (name) {
this.__super__(name); // Husky.prototype.__super__ = Dog
// What will happen by calling super here?
// 1. call `Dog.call(this, name)`
// 2. call `this.__super__(name)` in Dog constuctor, but `this` point to Husky instance
// 3. call `Dog.call(this, name)` again, because the `this` never changed
// ... dying circle
}
}, Dog);If we want to fix this, we need to write a compiling function automatically compute how many layers should find up to the proper ancestor. I did this a few years before, but finally it was abandoned. Because it is not a good way by compiling all method, or even only compiling the We can make a compromise on this which avoid parent class name to be called in subclass by using var Husky = Constructor({
constructor: function (name) {
Husky.__super__.call(this, name)
},
shout: function () {
Husky.__super__.prototype.shout.call(this);
}
}, Dog);But we can't go further. |
newoperator for new class definition. Change to directly function invoking.__super__keyword. Because it may confuse user when usingthis.__super__.xxxto invoke method from 2 or more layer upper.README.mdand do some typo fix.