javascript - [].shift.call( arguments )和 [ ].slice.call( arguments )怎么理解

查看:172
本文介绍了javascript - [].shift.call( arguments )和 [ ].slice.call( arguments )怎么理解的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问 题

Function.prototype.bind = function(){
        var self = this, 
        context = [].shift.call( arguments ), 
        args = [].slice.call( arguments );
        return function(){
        return self.apply( context, [].concat.call( args, [].slice.call( arguments ) ) );
    }
    };
    var obj = {
        name: 'sven'
    };
    var func = function( a, b, c, d ){
        alert ( this.name ); 
        alert ( [ a, b, c, d ] ) 
    }.bind( obj, 1, 2 );
    func( 3, 4 )

解决方案

已经知道了,借用Array.protptype原型上的方法对传进来的参数进行一个操作

这篇关于javascript - [].shift.call( arguments )和 [ ].slice.call( arguments )怎么理解的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆