I was looking over the code for qunit.
My question is why would you want to attach the qunit object via property to window object.
Here is the link to the file. Look at line 11.
If I look at a unit test run using firebug you can see it is a property of window.
[edit] Additional: Is there a specific reference for best practice for declaring things in specific namespaces?
All global objects (functions, variables, etc) are just children of window, it's the default context.
For example: window.jQuery
or window.$
It may be easier to think of it this way...where else would you put them? When you're doing something this general, best (or at least easiest) to stick them in the default place. If you're doing something complex with lots of functions, objects, etc...best to put them in a namespace or within an object. For example all of jQuery's code is under jQuery
, not littered in the root of the DOM like window.ajax
, instead it's jQuery.ajax
.
This is much neater, but perhaps overkill when you're dealing with a few items, but it's a good idea to make sure they are unique if this is the case...which qunit does, by prefixing their objects with qunit-
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With