Cell Shock
New Member
I am trying to settle on a method that will provide me the most elegant way of wrapping my code in \[code\]Namespace\[/code\]/\[code\]Unit\[/code\] like objects. For example Google Maps API's \[code\]var a = Google.Maps.Foo();\[/code\], which I think seems quite clean. I'd like it to enclose (if that is the right term) the \[code\]jQuery\[/code\] \[code\]No Conflict\[/code\] \[code\]$\[/code\] sign as well.So far I am liking:\[code\]// Top level container for sub objectsvar myApp = myApp || {}; // An object to be held in myApp (function( skillet, $, undefined ) { //Private Property var isHot = true; //Public Property skillet.ingredient = "Bacon Strips"; //Public Method skillet.fry = function() { var oliveOil; addItem( "\t\n Butter \n\t" ); addItem( oliveOil ); console.log( "Frying " + skillet.ingredient ); return "Fried!"; }; //Private Method function addItem( item ) { if ( item !== undefined ) { console.log( "Adding " + $.trim(item) ); } } }( window.myApp.skillet = window.myApp.skillet || {}, jQuery ));\[/code\]Can anyone expand on this, point out potential problems, or just offer a better methodology in general?