create【作成】
assign【プロパティ コピー】

Object.create【作成】

メモ

概要

  • オブジェクトを作成

関連

外部リンク (英語)

Object.create ( O, Properties )
ES2022 (13) ES2021 (12) ES2020 (11)

構文

Object.create( O [, Properties] ) 

 オブジェクト
O オブジェクト
Properties プロパティ (プロパティ名 + 属性:詳細は下記参照)

TypeError 例外 O (オブジェクト)がオブジェクト・null 以外
Properties (プロパティ)の属性
属性デフォルト値
valueundefined
getundefined
setundefined
writablefalse
enumerablefalse
configurablefalse

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 例外