Skip to content

Instantly share code, notes, and snippets.

@kwyn
Last active August 29, 2015 13:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kwyn/9959920 to your computer and use it in GitHub Desktop.
Save kwyn/9959920 to your computer and use it in GitHub Desktop.
var trampoline = function(fun){
var args = Array.prototype.slice.call(arguments,1);
var result = fun.apply(this, args);
while(typeof result === 'function') {
result = result();
}
return result;
};
var countDown = function(n){
if(n === 0){
alert("Happy new year!");
return;
}
var thunk = function(){return countDown(n-1);};
return thunk;
};
trampoline(countDown, 5);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment