Created
June 30, 2014 12:42
-
-
Save toddmotto/49c16d931a7380a1e661 to your computer and use it in GitHub Desktop.
Even smaller Object extend() method, with no reference cloning: http://jsfiddle.net/LR639
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
function extend (target, source) { | |
var a = Object.create(target); | |
Object.keys(source).map(function (prop) { | |
prop in a && (a[prop] = source[prop]); | |
}); | |
return a; | |
}; |
Also i sounded quite arrogant there sorry, tried to change my comment but GitHub keeps throwing an error when i try :)
Hi @toddmotto! What you think about this?
function extend(target, source) {
return Object.assign({}, defaults, options);
};
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
In your example the target is set as your objects prototype possible duplicates set as properties.
The prototype accessible one has the original value whilst the property one has the new value. This is according the Chrome and IE's dev tools however.
Was this intended?
See my updated fiddle it explains it better,
http://jsfiddle.net/LR639/1/