Skip to content

Instantly share code, notes, and snippets.

@zzuhan
Created October 29, 2013 01:37
Show Gist options
  • Save zzuhan/7207849 to your computer and use it in GitHub Desktop.
Save zzuhan/7207849 to your computer and use it in GitHub Desktop.
check helpers function
// ECMAScript 5
function isEmpty(obj){
return Object.getOwnPropertyNames(obj).length === 0;
}
function isEmpty(obj){
return Object.keys(obj).length === 0;
}
// compitable
function isEmpty(obj){
for(var prop in obj) {
if(obj.hasOwnProperty(prop)) {
return false;
}
}
return true;
}
// jQuery
jQuery.isEmptyObject({}); // true
jQuery.isEmptyObject({'foo':'bar'}) // false
// Helpers
function isSet(val){
return typeof val == 'undefined';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment