Skip to content

Instantly share code, notes, and snippets.

@jefsnare
Created October 30, 2013 12:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jefsnare/7232239 to your computer and use it in GitHub Desktop.
Save jefsnare/7232239 to your computer and use it in GitHub Desktop.
JS pattern
// top-level namespace
var myApp = myApp || {};
// directly assign a nested namespace
myApp.library = {
foo:function(){
//...
}
};
// deep extend/merge this namespace with another
// to make things interesting, let's say it's a namespace
// with the same name but with a different function
// signature: $.extend( deep, target, object1, object2 )
$.extend( true, myApp, {
library:{
bar:function(){
//...
}
}
});
console.log("test", myApp);
// myApp now contains both library.foo() and library.bar() methods
// nothing has been overwritten which is what we're hoping for.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment