Created
November 17, 2012 02:02
-
-
Save jharding/4092624 to your computer and use it in GitHub Desktop.
Extend function that plays nice with setters and getters
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(obj) { | |
var slice = Array.prototype.slice; | |
slice.call(arguments, 1).forEach(function(source) { | |
var getter | |
, setter; | |
for (var key in source) { | |
getter = source.__lookupGetter__(key); | |
setter = source.__lookupSetter__(key); | |
if (getter || setter) { | |
getter && obj.__defineGetter__(key, getter); | |
setter && obj.__defineSetter__(key, setter); | |
} | |
else { | |
obj[key] = source[key]; | |
} | |
} | |
}); | |
return obj; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment