Syntax
const instance = Object.create(prototype);
Object.getPrototypeOf(instance);Examples
Prototype Delegation and Object.create: working example
Run this standalone example in a modern browser console unless another environment is specified. Expected result: Logs are Task: Review, false, and true.
const shared = {
describe() { return `Task: ${this.title}`; }
};
const task = Object.create(shared);
task.title = "Review";
console.log(task.describe());
console.log(Object.hasOwn(task, "describe"));
console.log(Object.getPrototypeOf(task) === shared);- Expected result: Logs are Task: Review, false, and true.
- describe is found on shared, but this is the object used at the call site.
- Only title is assigned directly to task in this example.
Best practices
- Avoid mutating shared prototypes during normal application work.
- Use Object.hasOwn when enumerating only a record’s own fields.
Runtime & versions
Browsers and JavaScript runtimes. Feature availability depends on the language and runtime version used by your project; consult the official reference below.
ECMAScript specification