2

If you're declaring namespaces in ASP.NET webforms, is it better to just use Type.registerNamespace or the usual way of var $Namespace = function() { }

3
  • Is this really related to ASP.Net? Commented Mar 25, 2011 at 1:42
  • I dunno. That's what I'm working on right now. Is Type not restricted to ASP.NET? Commented Mar 25, 2011 at 2:01
  • Yeah sorry, it's an MS AJAX thing. Commented Mar 25, 2011 at 2:57

2 Answers 2

2

Here is a blog post describing Type.registerNamespace: http://dotnetslackers.com/Community/blogs/bmains/archive/2009/05/30/ajax-and-type-registernamespace-how-it-works.aspx
Basically the two methods are the same thing.
If you're using MS AJAX then go with Type.registerNamespace, otherwise stick to plain ol' JavaScript.

Sign up to request clarification or add additional context in comments.

Comments

2

I prefer Type.registerNamespace(...) because it already handles creating sub-namespaces for you and won't overwrite existing namespaces.

Suppose you want to declare a namespace "A.B.C". Then you're talking about the difference between writing:

if(typeof A === "undefined") { A = function() { }; }
if(typeof A.B === "undefined") { A.B = function() { }; }
if(typeof A.B.C === "undefined") { A.B.C = function() { }; }

and:

Type.registerNamespace("A.B.C");

Obviously the latter is a time-saver and easier to read after the fact.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.