function classA(sscolor){
  this.color=sscolor;
  this.saycolor=function(){
    alert(this.color);
  };
}
function classB(scolor,sname){
  this.method=classA;
  this.method(scolor);
  delete this.method;
  this.name=sname;
  this.sayname=function(){
    alert(this.name);
  };
}
var obja=new classA("red");
var objb=new classB("blue","coolboy");
obja.saycolor();
objb.saycolor();
objb.sayname();

解决方案 »

  1.   

    基础性问题,给你个办法,自己一行行跟踪一下就明白了
    保存为aaa.htm后用IE打开(前提,机器上至少安装OFFICE)
    <script>
    function classA(sscolor){
      this.color=sscolor;
      this.saycolor=function(){
      alert(this.color);
      };
    }
    function classB(scolor,sname){
      this.method=classA;
      this.method(scolor);
      delete this.method;
      this.name=sname;
      this.sayname=function(){
      alert(this.name);
      };
    }
    debugger
    var obja=new classA("red");
    var objb=new classB("blue","coolboy");
    obja.saycolor();
    objb.saycolor();
    objb.sayname();
    </script>
      

  2.   

    就这3行代码不怎么明白
      this.method=classA;
      this.method(scolor);
      delete this.method;
      

  3.   

      this.method=classA;=>给本对象自定义一个method的成员,这里其实是当方法了,并且指向classA对象
      this.method(scolor);=>给这个方法赋值,其实就是给classA传一个参数
      delete this.method;=>删除这个this.method成员
      

  4.   

      this.method=classA;=>将方法classA拷贝到该对象的method方法里
      this.method(scolor);=>执行method方法
      delete this.method;=>删除这个this.method成员