Debugging JavaScript on the iPhone

posted by admin on 2010.05.04, under Uncategorized
04:

Quick tip, if your trying to debug your web app on the iPhone simulator or a device you can switch on the Debug console by going into Settings > Safari > Developer. It’s all explained in the Safari Web Content Guide written by the nice people at Apple.

JavaScript Singleton Pattern

posted by admin on 2010.04.23, under Uncategorized
23:

It may have taken 15/20 minutes of Google’ing to find an actual Singleton Pattern replicated in JavaScript, but it was worth it. Anyway I thought I would share. Thanks to this post for giving me what I wanted! Most of the answers Google turfed up for me didn’t return a persistent object, which is required by the Singleton Pattern. You can learn more about patterns in JavaScript with Pro JavaScript Design Patterns, although be warned it’s a very fast paced book and expects you to have a very good aptitude for learning. I have had to re-read some of the pages more than three times to understand precisely what’s going on, there is no doubt that the author is an exceptional JavaScript developer, but he explains things so quickly it’s almost like he presume you should know it already.

The Singleton Pattern

var Application = window.Application || {}; // Creates a namespace called Application.

Application.Config = function () {
    var instance = (function () {
        var privateVar;

        function privateMethod() {
            return 'privateMethod';
        }

        return { // Public interface.
            publicMethod: function () {
                return privateMethod();
            }
        }
    })();

    Application.Config = function() {
        return instance;
    }

    return Application.Config();
}

pagetop