Skip to content

Instantly share code, notes, and snippets.

@clofresh
Created August 4, 2011 02:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save clofresh/1124363 to your computer and use it in GitHub Desktop.
Save clofresh/1124363 to your computer and use it in GitHub Desktop.
$.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])
}
})
$.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