Click to Rate and Give Feedback
MSDN
MSDN Library
.NET Development
.NET Framework 3.5
ASP.NET Reference
Client Reference
Global Namespace
Type Class
Type Methods
 registerNamespace Method
Collapse All/Expand All Collapse All
This page is specific to
Microsoft Visual Studio 2008/.NET Framework 3.5

Other versions are also available for the following:
Type.registerNamespace Method

Creates a namespace. This member is static and can be invoked without creating an instance of the class.

Type.registerNamespace(namespacePath)
namespacePath

A string that represents the fully qualified namespace to register.

Exception type

Condition

Error.argument

(Debug) namespacePath contains invalid characters.

Error.invalidOperation

(Debug) namespacePath is not a valid namespace.

Use the registerNamespace method to create a namespace. A namespace is a region of scope that enables you to organize code. This is especially useful in large projects. By using namespaces, you can group classes. Each class name is then qualified by its namespace, which gives you a way to create globally unique class names.

Within a namespace, you can declare one or more of the following classes:

  • Another namespace

  • A class

  • An interface

  • An enumeration

  • A delegate

A fully qualified class name includes its namespace delimited with the . (dot) operator, such as MyNamespace.MyType. A namespace name can include upper or lowercase letters in the range A–Z and integers in the range of 0-9.

The following example shows how to use the registerNamespace method to register the namespace Samples.

JavaScript
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html  >
<head id="Head1" runat="server">
    <title>Sample</title>
</head>
<body>
    <form id="form1" runat="server">
       <asp:ScriptManager runat="server" ID="ScriptManager1">
       </asp:ScriptManager>

       <script type="text/javascript">
        // Register classes to test.
        Type.registerNamespace('Samples');

        Samples.A = function()
        {
            // Initialize as a base class.
            Samples.A.initializeBase(this);
        }

        Samples.B = function(){}
        Samples.C = function(){}

        Samples.A.registerClass('Samples.A');
        Samples.B.registerClass('Samples.B', Samples.A);

        Samples.C.registerClass('Samples.C');

        var isDerived;
        isDerived = Samples.B.inheritsFrom(Samples.A);
        // Output: "true".
        alert(isDerived);

        isDerived = Samples.C.inheritsFrom(Samples.A);
        // Output: "false".
        alert(isDerived);

        </script>
    </form>

</body>
</html>

Reference

Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Processing
© 2009 Microsoft Corporation. All rights reserved. Terms of Use | Trademarks | Privacy Statement | Site Feedback
Page view tracker