Created
March 24, 2016 10:06
-
-
Save yuchuanxi/91924d1a9085dcc4f832 to your computer and use it in GitHub Desktop.
partial
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* | |
* @authors yuChuanXi (http://yuchuanxi.com, wangfei.f2e@gmail.com) | |
* @date 2016-03-24 17:43:55 | |
* @title title | |
* @description description | |
*/ | |
'use strict'; | |
// 部分参数函数 | |
function partial ( fn ) { | |
var args = Array.prototype.slice.call(arguments, 1); | |
return function () { | |
var arg = 0; | |
for (var i = 0; i < args.length && arg < arguments.length; i++) { | |
if ( args[i] === undefined ) { | |
args[i] = arguments[arg++] | |
} | |
} | |
return fn.apply(this, args); | |
}; | |
}; | |
var delay = partial(setTimeout, undefined, 100); | |
delay(function () { | |
console.log(111) | |
}); | |
console.log(222) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment