curry function test
Function.prototype.curry = function() { var fn = this, args = Array.prototype.slice.call(arguments); // alert(fn); // function slice() { native code } // alert(args); // 2 return function() { // alert(this); // ['t', 'e', 's', 't'] // alert(args.concat(Array.prototype.slice.call(arguments))); return fn.apply(this, args.concat(Array.prototype.slice.call(arguments))); };};var arr = 'test'.split('');Array.prototype.yaslice = Array.prototype.slice.curry(2);alert(arr.yaslice(3));// arr.slice(2,3) => 's' |