Object.create(proto) tạo object mới với prototype là proto.
Object con dùng được method từ proto qua prototype chain.
javascript
const parent = { greet() { return 'Hi!'; } };
const child = Object.create(parent);
child.greet(); // 'Hi!' — inherited
child.hasOwnProperty('greet'); // false — not own
// Object.create(null) — object không có prototype
const dict = Object.create(null);
'toString' in dict; // false — thật sự sạchObject.create(proto) creates a new object whose prototype is proto.
The child can use methods from proto via the prototype chain.
javascript
const parent = { greet() { return 'Hi!'; } };
const child = Object.create(parent);
child.greet(); // 'Hi!' — inherited
child.hasOwnProperty('greet'); // false — not own
// Object.create(null) — object with no prototype
const dict = Object.create(null);
'toString' in dict; // false — truly clean