Skip to content

Instantly share code, notes, and snippets.

@roundcorners
Created February 1, 2012 18:24
Show Gist options
  • Save roundcorners/1718467 to your computer and use it in GitHub Desktop.
Save roundcorners/1718467 to your computer and use it in GitHub Desktop.
Checking properties before assignment
// These checks ensure the namespace is only created if it doesn't already exist.
var myNamespace = myNamespace || {},
// A check is required for each subsequent property of the namespace
application = myNamespace.application || {},
myFunc = myNamespace.application.anotherProperty.myFunc || function () {
// function definition...
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment