Created
August 21, 2012 17:46
-
-
Save bendman/3417810 to your computer and use it in GitHub Desktop.
Inheritance Test
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
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