Object.create ( O, Properties ) | ||
---|---|---|
ES2022 (13) | ES2021 (12) | ES2020 (11) |
Object.create( O [, Properties] )
オブジェクト
O オブジェクト
Properties プロパティ (プロパティ名 + 属性:詳細は下記参照)
TypeError 例外 O (オブジェクト)がオブジェクト・null 以外
属性 | デフォルト値 |
---|---|
value | undefined |
get | undefined |
set | undefined |
writable | false |
enumerable | false |
configurable | false |
const prop = { x: { value:0, writable:true }, y: { value:0 } };
const point = Object.create(Object.prototype, prop);
console.log(point);
// 出力:Object {x: 0, y: 0}
point.x = 10;
point.y = 10;
console.log(point);
// 出力:Object {x: 10, y: 0}
const ng = Object.create(123);
// TypeError 例外