Dela via


WinJS.Namespace.define function

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

Syntax

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

Parameters

  • name
    Type: string

    The name of the namespace. This could be a dot-separated name for nested namespaces.

  • members
    Type: object

    The members of the new namespace.

Return value

Type: Object

The newly-defined namespace.

Remarks

WinJS.Namespace.define and WinJS.Class.define provide special handling for objects of members that look like property descriptors. The property descriptors can only be one of two types: a data descriptor or an accessor descriptor. A data descriptor is a property that has a value, which may or may not be writable. An accessor descriptor is a property described by a getter-setter pair of functions.

Additionally, and unless otherwise specified via the property descriptor, properties which have a name that begin with an underscore are marked as unnumerable.

Examples

The following code shows how to use this function to define a Robotics namespace with a single Robot class.

WinJS.Namespace.define("Robotics", {
    Robot: WinJS.Class.define( function(name) {
            this.name = name;
        }, 
        { modelName: "" }, 
        { harmsHumans: false, obeysOrders: true })
});
var myRobot = new Robotics.Robot("Mickey");

myRobot.modelName = "4500";
var harm = Robotics.Robot.harmsHumans;

Requirements

Minimum WinJS version

WinJS 1.0

Namespace

WinJS.Namespace