Created
November 1, 2012 15:34
-
-
Save monolithed/3994364 to your computer and use it in GitHub Desktop.
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
/* extend | |
* | |
* @param {object} from | |
* @param {object} to | |
* @param {Array} [ array ] - array of properties | |
* | |
* using: | |
* extend(object_1, object_2); // clone object | |
* extend(object_1, object_2, ['foo', 'bar']); // take some properties | |
* | |
*/ | |
function extend(from, to, array) | |
{ | |
if (Array.isArray(array)) { | |
var comment = null; | |
array.forEach(function(item, index) { | |
comment = item + '__comment'; | |
if (from[comment]) | |
to[comment] = from[comment]; | |
to[item] = from[item]; | |
}); | |
} | |
else to = Object.create(from); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment