Skip to content

Instantly share code, notes, and snippets.

@zykadelic
Created June 27, 2014 11:39
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save zykadelic/149de288a3917d0cf310 to your computer and use it in GitHub Desktop.
Save zykadelic/149de288a3917d0cf310 to your computer and use it in GitHub Desktop.
Returns a new object with only the keys provided as arguments, leaves old object intact
if(!Object.prototype.slice){
Object.prototype.slice = function(){
var returnObj = {};
for(var i = 0, j = arguments.length; i < j; i++){
if(this.hasOwnProperty(arguments[i])){
returnObj[arguments[i]] = this[arguments[i]];
}
}
return returnObj;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment