-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
JavaScript函数系列骚操作系列 #9
Labels
Comments
偏函数
|
惰性函数 var foo = function() {
var t = new Date();
foo = function() {
return t;
};
return foo();
}; |
function compose() {
var args = arguments;
var start = args.length - 1;
return function() {
var i = start;
var result = args[start].apply(this, arguments);
while (i--) result = args[i].call(this, result);
return result;
};
}; function compose(...funcs) {
if (funcs.length === 0) {
return arg => arg
}
if (funcs.length === 1) {
return funcs[0]
}
return funcs.reduce((a, b) => (...args) => a(b(...args)))
} |
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
柯里化
The text was updated successfully, but these errors were encountered: