Added mergeProperties function to Object.prototype

Change-Id: I50346029a9bd8a7d2cf954b0cca011f73a6fae07
This commit is contained in:
Subramanya Sastry 2012-07-12 15:39:38 -05:00
parent d994d1292e
commit 2ee1514552

View file

@ -6,3 +6,14 @@
if(!Array.prototype.last) Object.defineProperty(Array.prototype, 'last', { if(!Array.prototype.last) Object.defineProperty(Array.prototype, 'last', {
value: function() { return this[this.length - 1] } value: function() { return this[this.length - 1] }
}); });
/** Good-old monkey-patching to let us merge properties of another object into this one. */
if(!Object.prototype.mergeProperties) Object.defineProperty(Object.prototype, 'mergeProperties', {
value: function (o) {
var self = this;
Object.keys(o).forEach(function(k) {
self[k] = o[k];
});
return this;
}
});