#20EasyQuiz
20. Prototype Chaining
JavaScriptOOP
Implement createChild(parentProto, ownProps) using Object.create so own properties shadow inherited prototype properties.
Example 1:
const animal = { eats: true };
const rabbit = createChild(animal, { jumps: true });
rabbit.eats; // true (inherited)
rabbit.jumps; // true (own)solution.js
Inherits from parentProto while keeping ownProps as own properties
(() => {
const parent = { role: "engineer" };
const child = createChild(parent, { name: "Satish" });
expect(child.role).toBe("engineer");
expect(Object.prototype.hasOwnProperty.call(child, "role")).toBe(false);
expect(Object.prototype.hasOwnProperty.call(child, "name")).toBe(true);
})()