Skip to content

Instantly share code, notes, and snippets.

@tregusti
Created August 22, 2013 15:07
Show Gist options
  • Save tregusti/6308425 to your computer and use it in GitHub Desktop.
Save tregusti/6308425 to your computer and use it in GitHub Desktop.
Allow easy modification to key/value objects.
function With( key, value ) {
this[key] = value;
return this;
};
function Except( key ) {
delete this[key];
return this;
};
exports.augment = function() {
if (Object.prototype.with && Object.prototype.with !== With) {
throw new Error("Object.prototype already contains a member 'with'.");
}
Object.prototype.with = With;
if (Object.prototype.except && Object.prototype.except !== Except) {
throw new Error("Object.prototype already contains a member 'except'.");
}
Object.prototype.except = Except;
}
exports.reset = function() {
if (Object.prototype.with === With)
delete Object.prototype.with;
if (Object.prototype.except === Except)
delete Object.prototype.except;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment