使用call来实现继承

    function Class1(arg1,arg2)
    {
        this.name = arg1;
        this.pass = arg2;
        this.showSub = function()
        {
            return this.name - this.pass;
        }
    }
    
    function Class2(arg1,arg2,arg3)
    {
        Class1.call(this,arg1,arg2);
        this.get3Arg = function()
        {
            return arg3;
        }
    }
    var class1 = new Class1(5,6);
    console.log(class1.showSub());
    var class2 = new Class2(10,1,12);
    console.log(class2.showSub());
    console.log(class2.get3Arg());

 

posted @ 2014-02-10 13:40  win_and_first  阅读(258)  评论(0编辑  收藏  举报