Last active
August 29, 2015 14:05
-
-
Save as3long/b1e2888c2c1e67ba6af8 to your computer and use it in GitHub Desktop.
js柯里化// source http://jsbin.com/lediro/2
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
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<title>JS Bin</title> | |
<style id="jsbin-css"> | |
.output{ | |
background:#aaa; | |
width:200px; | |
height:200px; | |
} | |
</style> | |
</head> | |
<body> | |
<div class="output"> | |
柯里化 | |
</div> | |
<script id="jsbin-javascript"> | |
function curry(fn){ | |
var args=Array.prototype.slice.call(arguments,1); | |
return function(){ | |
var innerArgs=Array.prototype.slice.call(arguments); | |
var finalArgs=args.concat(innerArgs); | |
return fn.apply(null,finalArgs); | |
}; | |
} | |
function add(num1,num2,num3){ | |
return num1+num2+num3; | |
} | |
var caaa=curry(add,5); | |
var cbbb=curry(caaa,4); | |
console.log(cbbb(3)); | |
</script> | |
</body> | |
</html> |
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
.output{ | |
background:#aaa; | |
width:200px; | |
height:200px; | |
} |
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 curry(fn){ | |
var args=Array.prototype.slice.call(arguments,1); | |
return function(){ | |
var innerArgs=Array.prototype.slice.call(arguments); | |
var finalArgs=args.concat(innerArgs); | |
return fn.apply(null,finalArgs); | |
}; | |
} | |
function add(num1,num2,num3){ | |
return num1+num2+num3; | |
} | |
var caaa=curry(add,5); | |
var cbbb=curry(caaa,4); | |
console.log(cbbb(3)); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment