WinJS - Call a Static Method or Property from an Instance

16 December, 2012

Wondering how you can call a static method or reach a static property of your WinJS class when all you have is an instance of it?

It’s actually simpler than I realised:

// Static Method
// or Static Property
var test = myInstance.constructor.staticProperty;

Keep in mind this for when you’re using the WinJS.Class.define structure as shown below:

var MyClass = WinJS.Class.define(
    function () {
        // Constructor Here
    }, {
        // Instance Members
    }, {
        // Static Members

var myInstance = new MyClass();