Created
May 8, 2010 16:30
-
-
Save jerodsanto/394634 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
// variable REDIRECT_TO may or may not be defined | |
// what I'd like to do (but raises ReferenceError): | |
var redirect_to = REDIRECT_TO || "/default/redirect/path"; | |
// working methods that I don't love | |
// 1 | |
if (typeof(REDIRECT_TO) != "undefined") | |
var redirect_to = REDIRECT_TO; | |
else | |
var redirect_to = "/default/redirect/path"; | |
// 2 | |
try { var redirect_to = REDIRECT_TO; } catch() { var redirect_to = "/default/redirect/path"; } | |
// SOLUTION - you can avoid the ReferenceError by using window.REDIRECT_TO: | |
var redirect_to = window.REDIRECT_TO || "/default/redirect/path"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment