ded / klass

a utility for creating expressive classes in JavaScript
751 stars 78 forks source link

Mixin calling its own thing instead of super's thing #24

Open bcowgill opened 9 years ago

bcowgill commented 9 years ago

I was looking at how the mixin code works. In the test case paraphrased below, If I wanted to implement a mixin where I called the Sub-class's thing before the implemented thing, how do you do that? Calling this.thing directly will just give an infinite loop.

test('should implement a wrapper method for mixins', 5, function () { ... inst.implement({ thing: function (n) { console.log('Implement#thing()'); ok(true, 'called implementer'); //this.supr(); would be called by subclass' thing, if we could this.thing(); // WARNING infinite loop. want to call the Sub's thing, not the base thing // this.myself(); would be a good expression for that this.boooshr(); }, boooshr: function () { console.log('Implement#boooshr()'); ok(true, 'called boooshr'); } }).thing();