Posted by & filed under User Interface.

I saw this little nugget in the Parse.com JavaScript library.  It took me a second to figure it out but once I got my head around it I started using it.  It is a very nice way to control your variable scoping in javascript.

//self executing function
(function(root) {
    //root is the global context

    //setup namespacing
    root.MyNamespace = MyNamespace || {};
    MyNamespace.Classes = MyNamespace.Classes || {};
    
})(this) // <- pass in the global context