On 7/11/07, Jörn Zaefferer <[EMAIL PROTECTED]> wrote:

Thanks Mike. Unfortuanetely that still leaves open the question of
method overriding and calling super methods. Maybe I'm just too used to
Java class system and therefore can't see how to effectively replace
those calls with something appropiate in JavaScript.


Here's something, based on Crokford's work, that I did for a project I'm
working on now:

var WidgetBase = {
   // ... other code ...
   /**
    * Prototypal inheritance
    *
    * Similar in many respects to jQuery.extend. This method, however,
provides
    * access back to the parent object, so you can still access it's
methods
    * if they've been overridden.
    *
    * Child classes can access their parent class via "this.parent"
    *
    * See: http://javascript.crockford.com/prototypal.html
    * @param Object obj
    */
   extend: function(obj) {
       var self = this;
       function F() {
           this.parent = self;
       }
       F.prototype = this;
       return jQuery.extend({}, new F(), obj);
   }
}

var aWidget = function() {};
aWidget.prototype = WidgetBase.extend({
   aMethod: function() {
       $.logger('overwrite');
       this.parent.aMethod();
   }
});

--
Aaron Heimlich
Web Developer
[EMAIL PROTECTED]
http://aheimlich.freepgs.com

Reply via email to