Ben Cull - Payments Engineer and Microsoft Development Professional

WinJS - Call a Static Method or Property from an Instance

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
myInstance.constructor.staticMethod();
// 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();

Simple.

WinJS - Call a Static Method or Property from an Instance
Prev post

Run Multiple SSL Websites on IIS6 Using a Wildcard Certificate

Next post

QuickEvent - A tiny javascript event engine

WinJS - Call a Static Method or Property from an Instance

Get in touch

Send me a message and I'll get back to you.