Created
February 1, 2012 18:24
-
-
Save roundcorners/1718467 to your computer and use it in GitHub Desktop.
Checking properties before assignment
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
// 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