Closed ghost closed 13 years ago
@kitgoncharov +1 on this. I'd love to see a working pull-request. Your examples provide enough insight — and as long as the interface remains the same, we could help in testing your integration.
Yeah that would be much appreciated, thanks for pointing that out!
+1 on this. For reference, I believe this is the approach Object.subClass() uses?
Closing this issue as per the discussion in pull request #6.
Currently,
Klass.js
wraps subclass methods by using function decompilation to detect a call tothis.supr()
and. This not only incurs a performance overhead, but exposes a leaky abstraction if the subclass method throws an exception. Consider the following example:In other words, if the subclassed method throws an exception, the original value of the
supr
method is not restored. A possible solution would be to wrap the execution of the method in atry...catch
block; however, this will result in additional detrimental effects to performance. Alternatively, we could remove wrapping entirely, and simply provide a reference to the original superclass method as a property on the subclassed method. Incidentally, this technique was previously outlined in an article by T.J. Crowder. I think it's more robust, both in terms of performance and mitigating leaky abstractions, than the wrapping technique thatKlass.js
currently uses. We've also adopted T.J.'s technique in FuseJS, in place of Prototype's more convoluted inheritance scheme.I would be happy to submit a pull request for this if you'd like, or even provide additional examples, but I'm interested in knowing if you think this is a good idea or not first.