Function.prototype.bind =
function
() {
var
fn =
this
;
var context = [].shilft.call(arguments);
var args= [].slice.call(arguments);
return
function
() {
return
fn.apply(context, [].concat.call(args, [].slice.call(arguments));
};
}
var
foo = {
x:
3
}
var
bar =
function
(a, b){
console.log(
this
.x);
console.log(a, b);
}
bar(2);
// undefined
var
boundFunc = bar.bind(foo, 1);
boundFunc();
// 3