As an alternative (not as an XOR, but just something else to ponder), how about allowing the 2nd argument to Class.create be a module-like function that returns the public interface of extension methods, and that function gets the superclass's prototype passed into it (and I think 'base' is a nice keyword for this)? Like...
var Pirate = new Class.create(Person, function(base) { //module pattern, private foo... var whatev1, whatev2...; //return public interface return { doStuff: function() { return base.doStuff.apply(this, arguments) + 'whatev'; } }; }); This way _no_ "clobbering" as kangax puts it, and nice simple "javascripty", yet "sugary" way to call the base class methods (and arguably could simply get rid of the awkward and overhead ridden $super mechanism)... Class.create could remain smart about this, detecting a function was passed in and calling it to get the extension... On Sun, Jan 4, 2009 at 6:12 PM, Tobie Langel <tobie.lan...@gmail.com> wrote: > > One of the downsides of the current $super-based implementations is > that it's ridiculously complicated to pass the whole set of arguments > to the parent's method (the equivalent of calling super without > passing any arguments in ruby): > > var Child = Class.create(Parent, { > doStuff: function($super) { > return $super.apply(null, Array.prototype.slice.call(arguments, > 1)) + ' extra stuff'; > } > }); > > The proposed implementation makes that dead easy and very > JavaScriptish: > > var Child = Class.create(Parent, { > doStuff: function() { > return this.applySuper('doStuff', arguments) + ' extra stuff'; > } > }); > > On the other hand, you'd have to handle this like so with your > proposed implementation: > > var Child = Class.create(Parent, { > doStuff: function() { > return this.getSuper('doStuff').apply(this, arguments) + ' extra > stuff'; > } > }); > > Which is a lot less elegant imho. > > If speed is a concern, we could very well imagine storing a reference > to the superclass's prototype in the sublcass's prototype itself, so > that Class#applySuper could be changed to: > > function applySuper(methodName, args) { > return this._super[methodName].apply(this, args); > } > > Finally, adding a base class seems like a good idea. > > > > > -- Ryan Gahl CEO Nth Penguin, LLC http://www.nthpenguin.com -- WebWidgetry.com / MashupStudio.com Future Home of the World's First Complete Web Platform -- Inquire: 1-920-574-2218 Blog: http://www.someElement.com LinkedIn Profile: http://www.linkedin.com/in/ryangahl --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Prototype: Core" group. To post to this group, send email to prototype-core@googlegroups.com To unsubscribe from this group, send email to prototype-core-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/prototype-core?hl=en -~----------~----~----~----~------~----~------~--~---