Let's say you have YAHOO.util.search and YAHOO.util.dom (making these
up). Both rely on a YAHOO.util namespace, but you can't assume that
that namespace has already been created. So you check to see if
YAHOO.util exists, and if not, make it. Otherwise you use the
pre-existing namespace.

On 20 June 2011 15:11, Philip Schweiger <[email protected]> wrote:
> In reading about the JavaScript namespacing or module patterns, I
> often see a step taken to avoid overwriting an existing object. For
> instance, at Eric Miragla's description of the module pattern (http://
> www.yuiblog.com/blog/2007/06/12/module-pattern/), he mentions that the
> YAHOO.namespace() method "assigns an empty object myProject as a
> member of YAHOO (but doesn’t overwrite myProject if it already
> exists)."
>
> I don't understand the utility of this - wouldn't it be better to
> throw an error instead? Presumably, if you are trying to assign a
> namespace that already exists, you were not aware of the prior
> existence of that namespace, so that is a coding error that you should
> be made aware of, and a signal to the script to stop further
> execution. If you DID already know of the existence of this namespace,
> I'd think you'd want a sort of "extend" method, NOT an assignment
> method. In neither case does it make sense that the script should just
> assume you knew what you were doing here and continue on. Am I missing
> something?
>
> Thanks!
>
> --
> To view archived discussions from the original JSMentors Mailman list: 
> http://www.mail-archive.com/[email protected]/
>
> To search via a non-Google archive, visit here: 
> http://www.mail-archive.com/[email protected]/
>
> To unsubscribe from this group, send email to
> [email protected]
>



-- 
Nick Morgan
http://skilldrick.co.uk
@skilldrick

-- 
To view archived discussions from the original JSMentors Mailman list: 
http://www.mail-archive.com/[email protected]/

To search via a non-Google archive, visit here: 
http://www.mail-archive.com/[email protected]/

To unsubscribe from this group, send email to
[email protected]

Reply via email to