Skip to content

Instantly share code, notes, and snippets.

@kaliaparijat
Created November 2, 2015 18:32
Show Gist options
  • Save kaliaparijat/c169f822efa36a21e174 to your computer and use it in GitHub Desktop.
Save kaliaparijat/c169f822efa36a21e174 to your computer and use it in GitHub Desktop.
function omit(obj, keys){
if (typeof obj != 'object') {
console.log("this is not an object");
return obj;
}
var omitThisKey;
if (keys instanceof Array) {
omitThisKey = function(key) {
if(keys.indexOf(key) > -1) {
return true;
}
};
}
else if (typeof keys == 'function') {
omitThisKey = keys.apply(key);
}
else if (typeof keys == 'object') {
omitThisKey = function(key) {
if (key == keys){
return true;
}
} ;
}
for(var key in obj) {
if(omitThisKey(key)) {
delete obj[key] ;
}
}
return obj;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment