Skip to content

Instantly share code, notes, and snippets.

@jharding
Created November 17, 2012 02:02
Show Gist options
  • Save jharding/4092624 to your computer and use it in GitHub Desktop.
Save jharding/4092624 to your computer and use it in GitHub Desktop.
Extend function that plays nice with setters and getters
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