Windows Dev Center

WinJS.Namespace.defineWithParent function

Applies to Windows and Windows Phone

Defines a new namespace with the specified name under the specified parent namespace. For more information, see Organizing your code with WinJS.Namespace.

Syntax


var object = WinJS.Namespace.defineWithParent(parentNamespace, name, members);

Parameters

parentNamespace

Type: object

The parent namespace.

name

Type: string

The name of the new namespace.

members

Type: object

The members of the new namespace.

Return value

Type: Object

The newly-defined namespace.

Remarks

If the name contains '.' it is split into parts that are taken to represent a hierarchy. The name following the last '.' will be the leaf namespace node to which the members will be added. Any namespace nodes along the path will be created as needed.

Namespaces should contain only classes, functions, constants, and other namespaces.

Examples

The following code shows how to use this function to define two namespaces: a Robotics namespace with a single Robot class; and a Robotics.Search namespace with a single member findRobot.


(function () {
    "use strict";

    var Robot = WinJS.Class.define(function (name) {
        this.name = name;
    });

    function getAllRobots() {
        return allRobots;
    }

    WinJS.Namespace.define("Robotics", {
        Robot: Robot
    });

    var allRobots = [
        new Robot("mike"),
        new Robot("ellen")
    ];

    function findRobot(robotName) {
        for (var i in allRobots) {
            if (allRobots[i].name == robotName) {
                return allRobots[i];
            }
        }
    }

    WinJS.Namespace.defineWithParent(Robotics, "Search",
        {
            findRobot: findRobot
        })
})();

Requirements

Minimum supported client

Windows 8 [Windows Store apps only]

Minimum supported server

Windows Server 2012 [Windows Store apps only]

Minimum supported phone

Windows Phone 8.1

Namespace

WinJS.Namespace

Library

Winjs.js

 

 

Show:
© 2015 Microsoft