I'm reading Crockford's book on Javascript and trying its inheritance method "Beget", but I'm puzzled by the result.
Could you explain why the following code returns "Values: blue_small / blue_big"? I would expect it to return "Values: blue_small / red_big".
if (typeof Object.beget !== 'function') {
Object.beget = function (o) {
var F = function () {};
F.prototype = o;
return new F();
};
}
function calculate(){
var object1 = {
color: "red",
size: "small"
};
var object2 = Object.beget(object1);
object2.size = "big";
object1.color = "blue";
return "Values: "+object1.color +"_" + object1.size +" \/ " + object2.color+"_" + object2.size || "unknown";
}