Created
February 1, 2011 10:00
-
-
Save livingston/805654 to your computer and use it in GitHub Desktop.
ES5 Extend & Clone Objects
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Object.defineProperties(Object, { | |
'extend': { | |
'configurable': true, | |
'enumerable': false, | |
'value': function extend(what, wit) { | |
var extObj, witKeys = Object.keys(wit); | |
extObj = Object.keys(what).length ? Object.clone(what) : {}; | |
witKeys.forEach(function (key) { | |
Object.defineProperty(extObj, key, Object.getOwnPropertyDescriptor(wit, key)); | |
}); | |
return extObj; | |
}, | |
'writable': true | |
}, | |
'clone': { | |
'configurable': true, | |
'enumerable': false, | |
'value': function clone(obj) { | |
return Object.extend({}, obj); | |
}, | |
'writable': true | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment