Skip to content

Instantly share code, notes, and snippets.

@Macil
Created December 17, 2014 23:14
Show Gist options
  • Save Macil/7369c93de844f8e785b0 to your computer and use it in GitHub Desktop.
Save Macil/7369c93de844f8e785b0 to your computer and use it in GitHub Desktop.
eval with chrome debugger support
function evalFromUrl(code, url) {
// jshint evil:true
// Q: Why put the code into a function before executing it instead of
// evaling it immediately?
// A: Chrome would execute it before applying any remembered
// breakpoints.
// Q: Why not just use `... = new Function(...)`?
// A: The sourcemaps would be off by one line in Chrome because of
// https://code.google.com/p/chromium/issues/detail?id=109362
// Q: indirectEval?
// A: Using the eval value rather than the eval keyword causes the
// code passed to it to be run in the global scope instead of the
// current scope. (Seriously, it's a javascript thing.)
var indirectEval = eval;
code = "(function(){"+code+"\n});\n//# sourceURL="+url+"\n";
var program = indirectEval(code);
program();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment