1. 程式人生 > >javascript除call函式外實現繼承的方式之一

javascript除call函式外實現繼承的方式之一

    function x(n){
        this.name=n;
        this.show=function(){
            alert(this.name);
        }
    }
    function y(n){

        this.__proto__=new x(n);
        this.constructor=y;
    }
    var s=new y("李四");

    s.show();

    function u(n){
        this.name=n;
        this.show=function(){
            alert(this.name);
        }
    }
    function v(n){
        u.call(this,n);
        this.constructor=v;
    }
    var k=new v("王五");
    alert(k.constructor);