Skip to content

Instantly share code, notes, and snippets.

@bendman
Created August 21, 2012 17:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bendman/3417810 to your computer and use it in GitHub Desktop.
Save bendman/3417810 to your computer and use it in GitHub Desktop.
Inheritance Test
var Builder = function(parentObj, childObj) {
var F = function() {};
F.prototype = parentObj;
return $.extend(new F(), childObj);
};
var parent = {
Inherit: 'parent inherit',
Both: 'parent value'
};
var childProps = {
ChildAndBelow: 'CAB value',
Both: 'child value'
};
var grandchildProps = {
ChildAndBelow: 'CAB second value',
JustMe: 'only the second child'
};
var child = Builder(parent, childProps);
console.log('child', child);
var grandchild = Builder(child, grandchildProps);
console.log('grandchild', grandchild);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment