Skip to content

Instantly share code, notes, and snippets.

@greut
Created March 12, 2009 13:08
Show Gist options
  • Save greut/78050 to your computer and use it in GitHub Desktop.
Save greut/78050 to your computer and use it in GitHub Desktop.
function extend(source, obj) {
for(var key in obj) {
if((obj[key].constructor === Array || typeof obj[key] !== "object") && obj.hasOwnProperty(key)) {
source[key] = obj[key];
} else {
source[key] = extend(source[key]||{}, obj[key]);
}
}
return source
}
function A(name) {
this.name = name;
}
A.prototype.toString = function() {
return "A: "+this.name;
};
function B(name) {
B.prototype.parent.apply(this, [name]);
}
B.prototype = extend(new A, {
parent: A,
constructor: B,
toString: function() {
return "B: "+this.name;
}
});
function C(name) {
C.prototype.parent.apply(this, [name]);
}
C.prototype = extend(new B, {
parent: B,
constructor: C,
toString: function() {
return "C: "+this.name;
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment