Skip to content

Instantly share code, notes, and snippets.

@aaronj1335
Last active May 25, 2023 17:11
Show Gist options
  • Save aaronj1335/5423021 to your computer and use it in GitHub Desktop.
Save aaronj1335/5423021 to your computer and use it in GitHub Desktop.
finding global variables

good unit tests framesworks in javascript will throw errors when you leak global variables. it can be massively difficult to trace down the offending lines of code in a large application. a quick and effective fix is to add the attached bit of javascript at the beginning of your application and open your debugger (chrome dev tools, firebug, node debugger, etc.).

you'll get a break point at the error and it's easy to fix from there.

// you can use 'global' if you're in node, though it's much easier to
// accidentally leak stuff on to the window object
Object.defineProperty(window, 'someGlobal', {
set: function() { debugger; }
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment