Created
March 7, 2019 21:00
-
-
Save xinleihuang/64d86a685a5adac7e2c85386d50ceaa9 to your computer and use it in GitHub Desktop.
JS Bin // source https://jsbin.com/mesapen
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"> | |
<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> |
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 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