Parent Prototype Revisited

Relates to DOM Scripting

Further to my post regarding referencing the current object as an instance of its prototype (aka superclass) via super simulation, I have realised by maintaining the correct constructor property value in the object's prototype there is no need to pass the object constructor to the parent prototype method of Object.


Object.prototype.parent = function() {
  var p = new Object();
  for (x in this.constructor.prototype) {
    if (x != "parent") {
      p[x.toString()] = this[x.toString()];          
    }
  }   
  return p;  
}

function BoxContainer(param) {
  Container.call(this, param); 
  var parent = this.parent();

  [..snip..]
}

BoxContainer.prototype = new Container;
BoxContainer.prototype.constructor = BoxContainer;

Where the last line is critical, since the value of constructor is initially overriden with the assignment of the BoxContainer prototype to reference Container.

Posted on Wednesday, Oct 13, 2004 at 02:30:21.

Comments on Parent Prototype Revisited (0)

Breadcrumbs Trail

[ Home ] -> TW Blog -> Oct 04 -> Parent Prototype Revisited
Site Map

The Severn Solutions website achieves the following standards:

[ XHTML 1.0 ] [ CSS 2 ] [ WAI AA ] [ Bobby AA ]

Page compiled in 0.016 seconds