Created
August 4, 2011 02:14
-
-
Save clofresh/1124363 to your computer and use it in GitHub Desktop.
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
$.get('/my_data_service', function(data) { | |
// Am I guaranteed that data.values will always be there and always will be an array? | |
for (var i in data.values) { | |
do_things(data.values[i]) | |
} | |
}) |
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
$.get('/my_data_service', function(data) { | |
// Write these kinds of checks enough times and your code starts to look like crap | |
if (data.values && data.values instanceof Array) { | |
for (var i in data.values) { | |
do_things(data.values[i]) | |
} | |
} else { | |
throw new Exception("Uh, wtf dude") | |
} | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment