Skip to content

Instantly share code, notes, and snippets.

@codylindley
Created March 14, 2012 04:02
Show Gist options
  • Save codylindley/2033972 to your computer and use it in GitHub Desktop.
Save codylindley/2033972 to your computer and use it in GitHub Desktop.
Find limit of recursion
var recurse = function(depth){
try{
return recurse(depth + 1);
}catch(ex){
return depth;
}
};
console.log(recurse(1));
@tbranyen
Copy link

Ha, I have some similar code in my LayoutManager Backbone plugin:

// In some browsers the stack gets too hairy, so I need to clear it
// and setTimeout is unfortunately the best way to do this.
try {
  LayoutManager.prototype.render.call(view, renderCallback);
} catch(ex) {
  // Such an obnoxious hack necessary to keep the browser from crashing.
  window.setTimeout(function() {
    LayoutManager.prototype.render.call(view, renderCallback);
  }, 0);
}

@codylindley
Copy link
Author

Nice!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment