Skip to content

Instantly share code, notes, and snippets.

@as3long
Last active August 29, 2015 14:05
Show Gist options
  • Save as3long/b1e2888c2c1e67ba6af8 to your computer and use it in GitHub Desktop.
Save as3long/b1e2888c2c1e67ba6af8 to your computer and use it in GitHub Desktop.
js柯里化// source http://jsbin.com/lediro/2
<!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>
.output{
background:#aaa;
width:200px;
height:200px;
}
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