Skip to content

Instantly share code, notes, and snippets.

@lushijie
Last active February 18, 2016 02:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lushijie/0d59335085103af8bb72 to your computer and use it in GitHub Desktop.
Save lushijie/0d59335085103af8bb72 to your computer and use it in GitHub Desktop.
函数柯里化
function Foo(x, y, z, w) {
var args = arguments;
if (args.length < Foo.length) {
return function() {
var oldArgs = Array.prototype.slice.call(args);
var newArgs = oldArgs.concat(Array.prototype.slice.call(arguments));
return args.callee.apply(null,newArgs);
}
} else {
return x + y - z * w;
}
}
console.log( Foo(1,4,3,2) ); //-1
console.log( Foo(1)(4)(3)(2) ); //-1
console.log( Foo(1,4)(3)(2) ); //-1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment