|
From: Raymond I. <xw...@ya...> - 2003-04-04 15:03:56
|
Hi,
I've been thinking about creating an easier way to
subclass/overwrite methods:
DynObject.prototype.subclass = function(n,fn){
if(!this._sbCls) this._sbCls=1;
var om = '_sbMethod'+(this._sbCls++); // old method
eval('fn='+(fn+'').replace(/\~subclass\(/g,'this.'+om+'('));
this[om]=this[n];
this[n]=fn;
};
Usage:
MyWidget.prototype.subclass('setSize',function(w,h){
~subclass(w,h); // call old setSize method;
// some code here
});
The above would subclass setSize() with the new
function. The ~subclass() function will allow you to
call the old/orginal setSize() function
It's similar to:
MyWidget.prototype._oldSetSize =
DynLayer.prototype.setSize;
MyWidget.prototype.setSize =
function('setSize',function(w,h){
this.oldSetSize(w,h); // call old setSize method;
// some code here
});
Is the term "subclass" correct or should we term it as
"overwrite"?
Any comments?
--
Raymond Irving
__________________________________________________
Do you Yahoo!?
Yahoo! Tax Center - File online, calculators, forms, and more
http://tax.yahoo.com
|