function C1(){} 
function C2(){} 
C2.prototype=new C1();
 function C3(){} 
C3.prototype=new C2(); 
var obj=new C3(); 
function C4(){} 
C3.prototype=new C4(); 
alert(obj instanceof C2);//true alert(obj instanceof C1);//true alert(obj instanceof C3);//false 
alert(obj instanceof C4);//false 这个是为什么啊

解决方案 »

  1.   


    function C1(){} 
    function C2(){} 
    C2.prototype=new C1();
     function C3(){} 
    C3.prototype=new C2(); 
    var obj=new C3(); 
    function C4(){} 
    C3.prototype=new C4(); 
    var obj1 = new C3();
    alert(obj instanceof C2);//true alert(obj instanceof C1);//true alert(obj instanceof C3);//false 
    alert(obj instanceof C4);//false 这个是为什么啊
    alert(obj1 instanceof C2);
    alert(obj1 instanceof C4);
      

  2.   


    function color(){}; //define color
    function colRed(){}; //define red colorcolor.prototype = new colRed(); //再次让color继承colRed
    var objRed1 = new color(); //第一次继承colRed的对象
    color.prototype = new colRed();//再次让color继承colRed
    var objRed2 = new color(); //第二次继承colRed的对象alert(objRed1 instanceof color); //false 这个为什么
    alert(objRed2 instanceof color); //true