Skip to content

Instantly share code, notes, and snippets.

@nessthehero
Last active March 27, 2018 14:59
Show Gist options
  • Save nessthehero/4730750 to your computer and use it in GitHub Desktop.
Save nessthehero/4730750 to your computer and use it in GitHub Desktop.
JavaScript Boilerplate

JS Boilerplate

Simple boilerplate I use to start JavaScript projects.

githalytics.com alpha

// We're cooking with globals, so we use namespaces to avoid conflicts
var Namespace = Namespace || {};
Namespace.Project = Namespace.Project || {};
Namespace.Project.init = function () {
}
// Expecting jQuery, but you could easily change this to some other method of window ready or dom ready
$(function () {
// Cached selectors
Namespace.Project.$elm = {};
// Arbitrary data (Comes after selectors so we can use them here)
Namespace.Project.data = {};
Namespace.Project.init();
});
@vernak2539
Copy link

@raganwald, had no clue about checking undefined with void 0. I guess you learn something new everyday

@jpillora
Copy link

I find AngularJS and RequireJS solves namespacing issues quite nicely

@nessthehero
Copy link
Author

@mattgoucher I do that as well. I suppose you could take the solution from @scottbert and just leave the global namespace part uncommented so that it remains in the global namespace.

@jfhbrook
Copy link

I like using browserify for this kind of thing. You have to do a static build step and async code loading is pretty much out of the question, but at least those requires look nice. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment