Created
September 20, 2010 14:47
-
-
Save arian/588002 to your computer and use it in GitHub Desktop.
Simple JavaScript function to copy values from one object to another
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
// Simple JavaScript function to copy values from one object to another | |
Object.copy = function(from, to, keys){ | |
l = keys.length; | |
while (l--) to[keys[l]] = from[keys[l]]; | |
return to; | |
}; | |
var obj1 = {foo: 'bar', temp: 'foo', bar: 'temp'}; | |
obj2 = {}; | |
console.log(Object.copy(obj1, obj2, ['foo', 'bar'])); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
:)