请问这两种原型继承方式有啥区别:
1.function father(){......};
function child(){.....};
child.prototype=father.prototype;
2.
function father(){......};
function child(){.....};
function F(){};
F.prototype=father.prototype;
child.prototype=new F();
3.function father(){......};
function child(){.....};
child.prototype=new father;
请问这三种方式各有什么优劣呢??为什么第二个要新添一个F呢?
请指教!~谢谢~~~

解决方案 »

  1.   

    js就是原型继承- -因为js没有真正意义上的类的概念
     http://blog.sina.com.cn/s/blog_6e52b8600100m7z7.html
      

  2.   

    在JavaScript中,继承可以通过三种手法实现原型链继承 使用apply、call方法 对象实例间的继承。
      

  3.   

    function child(){.....};
    child.prototype指向类似child的一个实例,对prototype赋值就是给child实例添加属性或者方法,child实例具有的属性和方法则child的其他实例也是具有的。所以我觉得
    child.prototype=new father;
    child.prototype=father.prototype;
    大体上相同,只是后者father上不是通过prototype设置的属性或者方法,child没有继承。新添一个F,就是说明F仅仅继承prototype设置的属性或者方法,即构造了一个中间类,这个类组合prototype设置的属性或者方法,child则对F这个中间类进行继承。
    <script type="text/javascript">
    function father(){this.c="attribute";this.b=function(){}};
    father.prototype.a = function(){};function child(){};
    child.prototype=father.prototype;
    var child = new child();
    alert(child.b);
    var father = new father();
    alert(father.b);
    </script>
      

  4.   

    b.prototype = a.prototype  这是单纯的原型继承;c.prototype = a.prototype; b.prototype = new c()  类的扩展以及完全继承(原型和实例)b.prototype = new a;  实例继承;