Metro应用中Class的定义与使用

定义一个Class使用下面方法
// A simple "class" definition - using WinJS to define a constructor function
    // and add some properties to it's prototype.
    var Rect = WinJS.Class.define(
        // Constructor function
        function () { },
        {
            // These members are added to the constructors prototype object. You
            // can define data here...
            x: 0,
            y: 0,
            width: 0,
            height: 0,

            // Or you can define member functions.
            area: function () { return this.width * this.height; },
            toString: function () {
                return "rectangle (" +
                [this.x, this.y, this.width, this.height].join(", ") +
                ")";
            }
        }
    );


使用的话
var rect = new Rect();

你可能感兴趣的:(Class)