Skip to content

Instantly share code, notes, and snippets.

Created April 11, 2016 15:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save anonymous/c7ee29126a3dcd86daebc012e145dff1 to your computer and use it in GitHub Desktop.
Save anonymous/c7ee29126a3dcd86daebc012e145dff1 to your computer and use it in GitHub Desktop.
JS Bin // source https://jsbin.com/pinade
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
</head>
<body>
<script id="jsbin-javascript">
function splat(fn) {
return function(array) {
// 充分利用了 apply 拆分数组的特性
return fn.apply(null, array);
};
}
// 传入一个函数,返回另外一个函数
var func = splat(function(x, y) {
return x + y;
});
func([1, 2]);
console.log(func([1, 5]));
</script>
<script id="jsbin-source-javascript" type="text/javascript">function splat(fn) {
return function(array) {
// 充分利用了 apply 拆分数组的特性
return fn.apply(null, array);
};
}
// 传入一个函数,返回另外一个函数
var func = splat(function(x, y) {
return x + y;
});
func([1, 2]);
console.log(func([1, 5]));</script></body>
</html>
function splat(fn) {
return function(array) {
// 充分利用了 apply 拆分数组的特性
return fn.apply(null, array);
};
}
// 传入一个函数,返回另外一个函数
var func = splat(function(x, y) {
return x + y;
});
func([1, 2]);
console.log(func([1, 5]));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment