Skip to content

Instantly share code, notes, and snippets.

@ashanbh
Created June 5, 2013 02:58
Show Gist options
  • Save ashanbh/5711315 to your computer and use it in GitHub Desktop.
Save ashanbh/5711315 to your computer and use it in GitHub Desktop.
JQuery NameSpace Declaration
(function(nameSpace) {
//Private Property
var myPrivateProperty = true;
//Private Method
function doSomething( item ) {
if ( item !== undefined ) {
console.log( "Adding " + $.trim(item) );
}
}
//Public Property
nameSpace.ingredient = "Bacon Strips";
//Public Method
nameSpace.sayHello = function() {
doSomething();
console.log( "Hello " );
};
}( window.MyNameSpace = window.MyNameSpace || {}));
//Adding New Functionality to the NameSpace
(function( nameSpace) {
//Public Method
nameSpace.toString = function() {
console.log( myPrivateProperty );
};
}( window.MyNameSpace = window.MyNameSpace || {}));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment