Skip to content

Instantly share code, notes, and snippets.

@xinleihuang
Created March 7, 2019 21:00
Show Gist options
  • Save xinleihuang/64d86a685a5adac7e2c85386d50ceaa9 to your computer and use it in GitHub Desktop.
Save xinleihuang/64d86a685a5adac7e2c85386d50ceaa9 to your computer and use it in GitHub Desktop.
JS Bin // source https://jsbin.com/mesapen
<!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 thunkify(fn) {
var args = [].slice.call(arguments, 1);
return function(cb) {
args.push(cb);
return fn.apply(null, args);
}
}
function foo(x, y, cb) {
setTimeout(function() {
cb(x+y);
}, 1000);
}
var fooThunk = thunkify(foo, 3, 4);
fooThunk(function(sum) {
console.log(sum);
});
console.log([].slice.call([1,2,3], 1).toString());
</script>
<script id="jsbin-source-javascript" type="text/javascript">function thunkify(fn) {
var args = [].slice.call(arguments, 1);
return function(cb) {
args.push(cb);
return fn.apply(null, args);
}
}
function foo(x, y, cb) {
setTimeout(function() {
cb(x+y);
}, 1000);
}
var fooThunk = thunkify(foo, 3, 4);
fooThunk(function(sum) {
console.log(sum);
});
console.log([].slice.call([1,2,3], 1).toString());</script></body>
</html>
function thunkify(fn) {
var args = [].slice.call(arguments, 1);
return function(cb) {
args.push(cb);
return fn.apply(null, args);
}
}
function foo(x, y, cb) {
setTimeout(function() {
cb(x+y);
}, 1000);
}
var fooThunk = thunkify(foo, 3, 4);
fooThunk(function(sum) {
console.log(sum);
});
console.log([].slice.call([1,2,3], 1).toString());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment