Last active
December 13, 2015 17:08
-
-
Save gustinmi/4945216 to your computer and use it in GitHub Desktop.
Shorten your boilerplate JavaScript code
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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