(function(){ var h = 0; handle =function(){return h++}; var f =function(){}; extend =function(a, b){ f.prototype= a; var ret =new f; if(typeof b =='function'){ b.call(ret); }elseif(typeof b =='object'){ for(varkeyin b){ ret[key]= b[key]; } } return ret; }; })();
ClassB.prototype= extend(ClassA.prototype,function(){ this[ClassA.virtualmethod]=function(){ alert('this is ClassA.virtualmethod, impl in ClassB.\nwill show this.hello.'); alert('this.hello = '+this.hello); }
var impl =this[ClassA.virtualmethod]; this[ClassA.virtualmethod]=function(){ alert('this is ClassA.virtualmethod, impl in ClassC. \nwill run ClassB\'s impl.'); impl.apply(this,arguments); }; }); })();
// test case
var a =new ClassA; a.virtualmethod();// not yet impl
var b =new ClassB; b.test(); alert('b.virtualmethod is: '+b.virtualmethod);