alert(objA.showColor());
            alert(objB.showColor());
            alert(objB.showName());
改成 
  
            objA.showColor();
           objB.showColor();
           objB.showName();再试试

解决方案 »

  1.   

    alert()的返回值为undefined 测试var s=alert("hello");alert(typeof s == "undefined");  //对话框显示为true
      

  2.   

    <script language="JavaScript">
                //父类
                function ClassA(sColor) {
                    this.color = sColor;
                    this.showColor = function() {
                        alert(this.color);
                    };
                }
                
                function ClassB(sColor, sName) {
                    //this.newMethod = ClassA;
                    //this.newMethod(sColor);
                    //delete this.newMethod;
                    //ClassA.call(this, sColor);
                    ClassA.apply(this, new Array(sColor));
                    
                    //创建新属性和方法
                    this.name = sName;
                    this.showName = function() {
                        alert(this.name);
                    };
                }
                
                // test
                var objA = new ClassA("blue");
                var objB = new ClassB("red", "apq");
                objA.showColor();//不是继承的问题 而是人方法里已经alert了 你又alert
                objB.showColor();
                objB.showName();
            </script>
      

  3.   

    你得到六个值的原因是:alert(objA.showColor()); 首先执行objA.showColor()方法 就是弹出个对话框 显示颜色然后又将这个对话框的返回值赋给外部的alert方法继续调用 所有得到了undefined 总共就有6个对话框弹出
      

  4.   

    呵呵,来CSDN就好了呀!!
    "alert()的返回值为undefined" 学习了...
    我最近都alert 迷糊了