Skip to main content

Windows Dev Center

WinJS.Namespace.define function

Applies to Windows and Windows Phone

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


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



Type: string

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


Type: object

The members of the new namespace.

Return value

Type: Object

The newly-defined namespace.


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.


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) {
   = name;
        { modelName: "" }, 
        { harmsHumans: false, obeysOrders: true })
var myRobot = new Robotics.Robot("Mickey");

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


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