Skip to content

Instantly share code, notes, and snippets.

@yuchuanxi
Created March 24, 2016 10:06
Show Gist options
  • Save yuchuanxi/91924d1a9085dcc4f832 to your computer and use it in GitHub Desktop.
Save yuchuanxi/91924d1a9085dcc4f832 to your computer and use it in GitHub Desktop.
partial
/**
*
* @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