The propertiesObject Parameter
You'll learn how to define properties with specific descriptors when creating objects using Object.create's optional second argument.
Beyond Simple Inheritance
So far, you've used Object.create(proto) to set up prototype chains. But Object.create actually accepts a second parameter that lets you define properties with full control over their descriptors right when you create the object.
The syntax looks like this:
const obj = Object.create(proto, propertiesObject);
The propertiesObject uses the same format as Object.defineProperties() — each key is a property name, and each value is a descriptor object.
How It Works
const animal = {
speak() {
return "Some sound";
}
};
const dog = Object.create(animal, {
name: {
value: "Buddy",
writable: true,
enumerable: true,
configurable: true
},
age: {
value: 3,
writable: false,
enumerable: true,
configurable: false
}
});
console.log(dog.name); // "Buddy"
console.log(dog.age); // 3
console.log(dog.speak()); // "Some sound"
dog.name = "Max"; // Works (writable: true)
dog.age = 4; // Fails silently (writable: false)
console.log(dog.age); // Still 3
Think of it like ordering a custom-built house: Object.create lays the foundation (prototype), while the propertiesObject lets you specify exactly how each room (property) should be built — locked doors, hidden rooms, or changeable furniture.
Why Use It?
This approach combines prototype setup with property definition in one step, giving you precise control over property behavior from the start.
Key Takeaway: The second parameter of Object.create lets you define own properties with full descriptor control while simultaneously setting the prototype, combining inheritance and property configuration in a single operation.