Function.prototype.bind

Function.prototype.bind = function () {app

    var fn = this ;this

    var context = [].shilft.call(arguments);spa

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

     return function () {code

         return fn.apply(context, [].concat.call(args, [].slice.call(arguments));io

     };console

}function

var foo = {call

     x: 3apply

}

 

var bar = function (a, b){

     console.log( this .x);

    console.log(a,  b);

}

 

bar(2); // undefined

 

var boundFunc = bar.bind(foo, 1);

 

boundFunc(); // 3

相關文章
相關標籤/搜索