function boxType(){
this.run=function(){
return true;
}
}
var _hjbglxx=function(){};
_hjbglxx.prototype=new boxType();
_hjbglxx.prototype.bglxBox=function(ele){
//opr code
}
_hjbglxx.prototype.run=function(){
alert(2);
   return true;
}
var hjbglxx=new _hjbglxx();我要hjbglxx变量继承boxType中的一个run方法,如果hjbglxx中有run,就覆盖.
现在这功能是实现了,很起来很复杂,
因为我要页面加载后这变量就能直接调用的,所以还很不情愿的加了这一段
var hjbglxx=new _hjbglxx();

解决方案 »

  1.   

    你是想hjbglxx也拥有boxType的run方法吧。那你为什么不直接在里面调用boxType的run方法呢。
      

  2.   


    因为我有可能 会出现 _hjbglxx2,_hjbglxx3,boxType.run函数是通用的..现在我改成这样的了,不知道 谁还有更好些的方法呢..function boxType(){
    this.run=function(){
    return true;
    }
    }function addBGLX(fn){//添加报告类型
    fn.prototype=new boxType();
    return new fn();
    }var hjbglxx=addBGLX(function(){//报告类型  为会计报告类参数

    this.run=function(kjField,kjValue){//会计报告类参数 赋值.验证

    //opr code
    return true;
    }
    });
      

  3.   


    //对象构造器,可以摒弃传统的new操作符来生成对象,也更好的诠释了js的基于原型的特点
    Object.beget=function(o){
      var F=function (){};
      F.prototype=o;
      return new F();
    }var hjbglxx=Object.beget(new boxType());
    hjbglxx.bglxBox=function(){};
    hjbglxx.run=function(){};
      

  4.   

         function boxType(){ 
    this.run = function(){ 
    return true; 

    }
    var _hjbglxx = function(){
    this.bglxBox = function(ele){ 
    //Todo...
    }
    }; 
    _hjbglxx.prototype = new boxType();
    _hjbglxx.constructor = boxType;

    var test = new _hjbglxx();
    alert(test.run());
      

  5.   

    上面有笔误。。     function boxType(){ 
    this.run = function(){ 
    return true; 

    }
    function _hjbglxx(){
    this.bglxBox = function(ele){ 
    //Todo...
    }
    }; 
    _hjbglxx.prototype = new boxType();
    _hjbglxx.prototype.constructor = _hjbglxx;

    var test = new _hjbglxx();
    alert(test.run());