call和apply的用途

153 阅读1分钟
        // 借用其他对象的方法
        var A = function( name ){
            this.name = name;
        };

        var B = function(){
            A.apply( this, arguments);
        };

        B.prototype.getName = function(){
            return this.name;
        }
        var b = new B( 'sven' );
        console.log(b.getName() ); // seven