I am learning JavaScript, and I have read somewhere the following code:
if (typeof Object.create !== 'function') {
Object.create = function (o) {
function F() {}
F.prototype = o;
return new F();
};
}
newObject = Object.create(oldObject);
I understand that the Object.create function return a new object which inherited the object o that has been passed as a parameter to the Object.create function. But, I don't understand what is the sense to make this? I mean, even the Object.create function returned a new object, but the new object and the old object has no difference. Even new object inherit old one, there are no new methods defined in the new object. So, in what situation do we need the above code to get the new object??