Skip to content

Instantly share code, notes, and snippets.

@gustinmi
Last active December 13, 2015 17:08
Show Gist options
  • Save gustinmi/4945216 to your computer and use it in GitHub Desktop.
Save gustinmi/4945216 to your computer and use it in GitHub Desktop.
Shorten your boilerplate JavaScript code
//Boiler plate code is usually consisted of simple patterns. Once you master them, there is no need for readability. It should be as compact as possible, to preserve space for the real implementation code. For example:
// adding interface "storage" to namespace "AppHtml5"
if (window.AppHtml5)
window.AppHtml5.storage = { "save" : {}, "load" : {}};
else {
window.AppHtml5 = {};
window.AppHtml5.storage = {};
window.AppHtml5.storage = { "save" : {}, "load" : {}};
}
// BETTER, shorter
window.AppHtml5 ? window.AppHtml5.storage = { "save" : {}, "load" : {}} : window.AppHtml5 = {"storage" : { "save" : {}, "load" : {}}};
//usage in code
window.AppHtml5.save("key1","val1" );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment