WinJS.Class.define function
Defines a class using the given constructor and the specified instance members.
Syntax
var object = WinJS.Class.define(constructor, instanceMembers, staticMembers);
Parameters
constructor
Type: FunctionA constructor function that is used to instantiate this type.
instanceMembers
Type: ObjectThe set of instance fields, properties, and methods made available on the type.
staticMembers
The set of static fields, properties, and methods made available on the type.
Return value
Type: Object
The newly-defined type.
Remarks
For more information about using this method, see Defining and deriving types with WinJS.Class. For information about using constructors to define types in JavaScript, see Using Constructors to Define Types.
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 method.
var Robot = WinJS.Class.define(
function (name) {
this.name = name;
},
{
modelName: "",
on: function () {
// Turn the robot on.
},
off: function () {
// Turn the robot off.
}
},
{
harmsHumans: false,
getModels: function () {
// Return all the available models.
}
});
var myRobot = new Robot("Mickey");
myRobot.modelName = "4500";
myRobot.on();
Robot.harmsHumans = false;
var models = Robot.getModels();
Requirements
Minimum WinJS version |
WinJS 1.0 |
Namespace |
WinJS.Class |