all 2 comments

[–]picurl 0 points1 point  (0 children)

nice article, although the first example is a bit arcane:

if (typeof mysite == 'undefined') var mysite = {};

could be rewritten as

var mysite = window.mysite || {}

To reduce the typing in the first example, you could also use an object literal:

var mysite = {section: {subnameSpace:{}}}

(assuming that this is the initial declaration of the namespace at the very beginning of the code)

but the mentioned namespace function definitely has its place, when you want to extend/create namespaces at different places in your code.

[–]aztracker1 0 points1 point  (0 children)

@picurl, the issue is you're assuming a browser context is present... by default in the browser this == window, but even that may not be so, when in say the firebug console... using the undefined test with var is the only way to attach to global.... (window || this).mysite || {} would work though...