Object.create()
Object.create(proto, propertiesObject?) Returns:
object · Updated March 13, 2026 · Object Methods object prototype oop
Object.create() creates a new object with a specified prototype object and optional property descriptors. This method is fundamental to JavaScript’s prototypal inheritance, allowing developers to explicitly set the prototype of an object at creation time rather than using constructor functions or Object.setPrototypeOf().
Syntax
Object.create(proto)
Object.create(proto, propertiesObject)
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
proto | object | null | The object which will be the prototype of the newly created object. Can be null for objects without a prototype. |
propertiesObject | object | undefined | An optional object whose enumerable own properties specify property descriptors to be added to the new object. |
Examples
Creating an object with a custom prototype
const personPrototype = {
greet() {
return `Hello, my name is ${this.name}`;
}
};
const person = Object.create(personPrototype);
person.name = 'Alice';
person.age = 30;
console.log(person.greet());
// Hello, my name is Alice
console.log(Object.getPrototypeOf(person) === personPrototype);
// true
Creating an object with property descriptors
const obj = Object.create(null, {
name: {
value: 'JavaScript',
writable: true,
enumerable: true,
configurable: true
},
version: {
value: 'ES5+',
writable: false,
enumerable: true,
configurable: false
}
});
console.log(obj.name);
// JavaScript
obj.name = 'TypeScript';
console.log(obj.name);
// TypeScript (writable: true)
console.log(obj.version);
// ES5+ (writable: false, cannot be changed)
Creating a null prototype object
const nullProto = Object.create(null);
nullProto.message = 'Hello';
console.log(Object.getPrototypeOf(nullProto));
// null
console.log(nullProto.hasOwnProperty);
// undefined - no inherited methods from Object.prototype
Common Patterns
Factory pattern with Object.create():
function createAnimal(name, species) {
return Object.create(Animal.prototype, {
name: { value: name, writable: true, enumerable: true },
species: { value: species, writable: true, enumerable: true }
});
}
const dog = createAnimal('Buddy', 'Dog');
console.log(dog.species); // Dog
Object pooling for performance-critical code:
const reusablePool = Object.create(null);
let poolIndex = 0;
const poolSize = 100;
function getFromPool() {
if (poolIndex < poolSize) {
return reusablePool[poolIndex++];
}
return Object.create(null);
}
See Also
- object::setPrototypeOf — Set prototype of object
- object::getPrototypeOf — Get prototype of object
- object::assign — Assign properties
- object::create — MDN documentation