Consider:
var MyApp = MyApp || {};
MyApp.doAlert = function(message) { alert(message); };
MyApp.doAlert("from MyApp");
and
(function(ns) {
ns.doAlert = function(message) {
alert(message);
};
})(window.MyApp2 = window.MyApp2 || {});
MyApp2.doAlert("from MyApp2");
They both work, and as far as I can tell, are essentially the same. The purpose being to declare a namespace.
Is there a benefit to one style over the other?