<script type="text/javascript">
 
        //prototype属性
        function Son() {             //子类
           var lastname = "sam";
        }
        function Father() {          //父类
           var firstname = "Shen";
        }
        Son.prototype = new Father();
        alert(Son.firstname +" " +Son.lastname);
            
    </script>
初学jS,哪错了

解决方案 »

  1.   

     Son.prototype  = {} 
      你重写了对象原型  导致son无法找到原型引用
      

  2.   

      function GetObj(objName) 
            {
                if (document.getElementById) 
                {
                    return eval('document.getElementById("' + objName + '")');
                }
                else 
                {
                    return eval('document.all'+objName);
                }
            }
    这句话干啥用的,啥意思
      

  3.   

     <script type="text/javascript">
     
           function Son() {             //子类
               this.lastname = "sam";//这里用var 代表私有属性,只能Son类内部使用
            }
            function Father() {          //父类
               this.firstname = "Shen";
            }
            Son.prototype = new Father();//Son继承Father
            var son1=new Son(); //实例化Son对象
            alert(son1.firstname +" " +son1.lastname); </script>