<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
 <HEAD>
  <TITLE> New Document </TITLE>
  <META NAME="Generator" CONTENT="EditPlus">
  <META NAME="Author" CONTENT="">
  <META NAME="Keywords" CONTENT="">
  <META NAME="Description" CONTENT="">
 </HEAD> <BODY>
  <SCRIPT LANGUAGE="JavaScript">
  <!--
  function Rect(config){
                this.width = config.width;
                this.height = config.height;
                this.area = function(){
alert(11);
};
        }        function myRect(config){
                Rect.call(this,config);
                this.name = config.name;
                this.area = function(){
//这里如何调用一下父类的area方法?
alert(22);
//最终效果,是先alert(11),然后alert(22);
                }
        }        var a =new myRect({width:1,heigth:2,name:3});
        a.area();
        
  //-->
  </SCRIPT>
 </BODY>
</HTML>

解决方案 »

  1.   

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
    <HTML>
     <HEAD>
      <TITLE> New Document </TITLE>
      <META NAME="Generator" CONTENT="EditPlus">
      <META NAME="Author" CONTENT="">
      <META NAME="Keywords" CONTENT="">
      <META NAME="Description" CONTENT="">
     </HEAD> <BODY>
      <SCRIPT LANGUAGE="JavaScript">
      <!--
          function Rect(config){
                    this.width = config.width;
                    this.height = config.height;
                    this.area = function(){    
                        alert(11);
                    };
            }        function myRect(config){
                    Rect.call(this,config);
                    this.name = config.name;
    var a = this.area
                    this.area = function(){
                        //这里如何调用一下父类的area方法?
    a();
                        alert(22);
                        //最终效果,是先alert(11),然后alert(22);
                    }
            }        var a =new myRect({width:1,heigth:2,name:3});
            a.area();
            
      //-->
      </SCRIPT>
     </BODY>
    </HTML>
    area 里面有this的话就杯具了     
      

  2.   


    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
    <HTML>
     <HEAD>
      <TITLE> New Document </TITLE>
      <META NAME="Generator" CONTENT="EditPlus">
      <META NAME="Author" CONTENT="">
      <META NAME="Keywords" CONTENT="">
      <META NAME="Description" CONTENT="">
     </HEAD> <BODY>
      <SCRIPT LANGUAGE="JavaScript">
      <!--
          function Rect(config){
                    this.width = config.width;
                    this.height = config.height;
                    this.area = function(){    
                        alert(11);
                    };
            }        function myRect(config){
            var r = new Rect(config); //你这里这样来调用Rect
                    this.name = config.name;
                    this.area = function(){
                r.area();   //这里就可以调用父类的area方法了。
                        //这里如何调用一下父类的area方法?
                        alert(22);
                        //最终效果,是先alert(11),然后alert(22);
                    }
            }        var a =new myRect({width:1,heigth:2,name:3});
            a.area();
            
      //-->
      </SCRIPT>
     </BODY>
    </HTML>
      

  3.   

    楼上的问题,他自己都说了,有个缺陷,不能使用this,那肯定不行啊。
      

  4.   

    你在外面先定一个  var that=this,然后在方法里面用that就是了
      

  5.   


    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
    <HTML>
     <HEAD>
      <TITLE> New Document </TITLE>
      <META NAME="Generator" CONTENT="EditPlus">
      <META NAME="Author" CONTENT="">
      <META NAME="Keywords" CONTENT="">
      <META NAME="Description" CONTENT="">
     </HEAD> <BODY>
      <SCRIPT LANGUAGE="JavaScript">
      <!--
          function Rect(config){
                    this.width = config.width;
                    this.height = config.height;
                    this.area = function(){    
                        alert(11);
                    };
            }        function myRect(config){
                    Rect.call(this,config);
                    this.name = config.name;
                    var a = this.area;
                    var that = this; //这里定义
                    this.area = function(){
                         //这里面就可以用that来调用相应的方法了。
                        //这里如何调用一下父类的area方法?
                        a();
                        alert(22);
                        //最终效果,是先alert(11),然后alert(22);
                    }
            }        var a =new myRect({width:1,heigth:2,name:3});
            a.area();
            
      //-->
      </SCRIPT>
     </BODY>
    </HTML>
      

  6.   

    楼上的写法还是有问题:
    见代码:<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
    <HTML>
     <HEAD>
      <TITLE> New Document </TITLE>
      <META NAME="Generator" CONTENT="EditPlus">
      <META NAME="Author" CONTENT="">
      <META NAME="Keywords" CONTENT="">
      <META NAME="Description" CONTENT="">
     </HEAD> <BODY>
      <SCRIPT LANGUAGE="JavaScript">
      <!--
          function Rect(config){
                    this.width = config.width;
                    this.height = config.height;
                    this.area = function(){    
                        alert(this.heigth);
                    };
            }        function myRect(config){
                    Rect.call(this,config);
                    this.name = config.name;
                    var a = this.area;
                    var that = this; //这里定义
                    this.area = function(){
                         //这里面就可以用that来调用相应的方法了。
                        //这里如何调用一下父类的area方法?
                        that.area();
                        alert(22);
                        //最终效果,是先alert(11),然后alert(22);
                    }
            }        var a =new myRect({width:1,heigth:2,name:3});
            a.area();
            
      //-->
      </SCRIPT>
     </BODY>
    </HTML>
      

  7.   

        function Rect(config) {
            this.width = config.width;
            this.height = config.height;    }
        Rect.prototype.area = function() {
            alert(this.width+" , "+this.height);
        }    function myRect(config) {        Rect.call(this, config);
            this.name = config.name;        this.area = function() {
                Rect.prototype.area.call(this, config);
                //这里如何调用一下父类的area方法?
                alert(22);
                //最终效果,是先alert(11),然后alert(22);
            }
        }    var a = new myRect({ width: 1, height: 2, name: 3 });
        a.area();
      

  8.   

    function Rect(config){
        this.width = config.width;
        this.height = config.height;
        this.area = function(){
            alert(11);
        }
    }
    function myRect(config){
        this.superClass = Rect;
        this.superClass(config);
        this.superArea =this.area;
        this.name = config.name;    this.area = function(){
            this.superArea();
            //这里如何调用一下父类的area方法?
            alert(22);
            //最终效果,是先alert(11),然后alert(22);
        }
    }var a =new myRect({width:1,heigth:2,name:3});
    a.area();
      

  9.   

    不错,竟然还有这种写法,
     this.superClass = Rect;
     this.superClass(config);
      

  10.   


    function Rect(config){}
    Rect.prototype.area = function(){
    alert("我是父方法");
    }
    function myRect(config){
    arguments.callee.prototype.constructor.prototype.area(); //子类里调用父方法area
    arguments.callee.prototype.area();//子类里调用重载方法area
    }
    myRect.prototype = new Rect();
    myRect.prototype.area = function(){
    alert("我是重载方法");
    }
    var rectObj = new myRect();
    rectObj.constructor.prototype.area();//子类实例调用父类方法area
    rectObj.area();//子类实例调用子类方法area
      

  11.   

    天啊,又来一种写法!此帖要火!
    不过楼上的写法“myRect.prototype = new Rect();” 比较诡异!
      

  12.   

    myRect.prototype = new Rect();
    这是灰常标准的javascript原型链继承的写法~~
      

  13.   

    11楼不是和2楼存在一样的问题么。
    area 里面this都是指向子类