Last active
August 29, 2015 14:11
-
-
Save pilgreen/c500ba4464a845f5dbf0 to your computer and use it in GitHub Desktop.
Vanilla Object extension
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.extend = function() { | |
var args = Array.prototype.slice.call(arguments); | |
var destination = args.shift(); | |
var i = 0; | |
while(i < args.length) { | |
var source = args[i]; | |
for(prop in source) { | |
if(Object.prototype.hasOwnProperty.call(source, prop)) { | |
if(typeof source[prop] === "object") { | |
destination[prop] = destination[prop] || {}; | |
arguments.callee(destination[prop], source[prop]); | |
} else { | |
destination[prop] = source[prop]; | |
} | |
} | |
} | |
i++; | |
} | |
return destination; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment