Below is my javascript code
function extend(Child, Parent) { var F = function(){}; F.prototype = Parent.prototype; Child.prototype = new F(); Child.prototype.constructor = Child; } function BController (){ } function AController (){ BController.call(this); } AController.prototype.dosomething=function(){ }
if i call
var g=new AController(); g.dosomething ();
everything is fine. But if I call (I hope AContronller inherits BController)
extend(AController,BController); var g=new AController(); g.dosomething ();
he always reports
g.dosomething is not a function
Method 2: if I change the Acontroller as
function AController ( ){ this.dosomethingNew=function(){ } }
and call
extend(AController,BController); var g=new AController(); g.dosomethingNew ();
everything will be fine.
Your comment is welcome.
source share