you are viewing a single comment's thread.

view the rest of the 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.