다음을 통해 공유


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: Function

    A constructor function that is used to instantiate this type.

  • instanceMembers
    Type: Object

    The 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