ryoakg
6/16/2016 - 7:31 AM

Function.prototype.bind.js

// Function.prototype.bind()
// from ES 5.1
// https://developer.mozilla.org/ja/docs/Web/JavaScript/Reference/Global_Objects/Function/bind
function sub(a,b){ return a - b; }
var sub_from_10 = sub.bind(null,10);
sub_from_10(3); //=> 7
sub_from_10(4); //=> 6

Math.max(1,2,3);                 //=> 3
Math.max.bind(null,1,2,3);       //=> [Function: bound max]
Math.max.bind(null,1,2,3)();     //=> 3
Math.max.bind(null,1,2,3)(4,5);  //=> 5