Last active
February 18, 2016 02:17
-
-
Save lushijie/0d59335085103af8bb72 to your computer and use it in GitHub Desktop.
函数柯里化
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
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