Web App Development

Logging namespace field addition and removal in Javascript

I've been trying to figure out if a Javascript library is leaking global variables that might change the behavior of a function when it is called multiple times. So I made namespaceLogger:

  • View fields that were added or removed since the previous log call
  • View all non-default fields in the global namespace (so you'll just see jQuery and $, but not location , Boolean or SVGAngle)
You can include or paste the raw javascript code to use it. For example, pasting it on the blog I get this:

Found 871 fields in namespace [object Window]
Found 334 special fields: XRegExp, SyntaxHighlighter, jstiming, tickAboveFold, a, b, c, f, g, h, i, j, k, setAttributeOnload, ___gcfg, ___gapisync, gapi, gadgets, shindig, osapi, google, hackhack, safeJSON, tamings___, bridge___, caja___, ___, friendconnect_serverBase, friendconnect_loginUrl, friendconnect_gadgetPrefix, f...
Full log in window.namespaceLogger.lastLog
> window.hi = "Hello!"
> window.namespaceLogger.log()
1 new field: hi
To change the namespace, call window.namespaceLogger.setNamespace.

Comments


Follow me on Twitter
I'm building monitoring tool for site speed and Core Web Vitals.
➔ Start monitoring your website or run a free site speed test