bind封装

145 阅读1分钟
      Function.prototype.bind = function(){

            var self = this;
            var context = [].shift.call(arguments)

            var args = [].slice.call(arguments)

            return function(){
                return self.apply(context,[].concat.call(args,[].slice.call(arguments)))
            }
        }

         // bind
         var obj = {
            getList (){
                console.log(arguments)
            }
        }
        console.log(obj.getList.bind(null,1,2)(3,4,5))