Can this JavaScript singleton be improved?
Once you start to chain properties or function calls, you incur performance penalty due to scope differences. It's best you keep the property/function depth to a minimum. This ain't Java or AS3 that needs deep namespacing.
What's the idea of getInstance()? Can't the singleton module itself be the instance?
Regarding the output image, it is correct. You get the first message at 440ms, then the singleton created the message at 442ms during init(). The next call you made is at 482ms. Since the instance was already created, the same message (the one created at 442ms) was used.


Here's a very short version of it. Basically, I just removed getInstance() and made DatapodManager the instance. No visible speed difference but you have shorter code. I also preserved the idea of it being a closure in case you ever needed private properties:

var DatapodManager = (function () {
    return {
        message: 'singleton message defined at: ' + getMilliseconds(),
        getMessage: function () {
            return this.message
        },
        id: '1234'
    }
}());