私は次のようなオブジェクトを持っています
var Profile = Object.create(null);
Object.defineProperties(Profile, {
id: {
value: "",
enumerable: true
},
name: {
value: "",
enumerable: true
},
active: {
value: true,
enumerable: true
}
});
ここで、Profile インスタンスを作成して ID と名前を付け、アクティブなデフォルトを true のままにしたいので、次のようにします。
var p1 = Object.create(Profile, {
id: {
value: "123",
enumerable: true
},
name: {
value: "hello world",
enumerable: true
}
});
次に、p1という名前のオブジェクトを取得しましたが、「アクティブ」が見つかりません
Object.getOwnPropertyNames(p1);
また、JSON.stringify(p1) を使用してプロパティ「アクティブ」をシリアル化することはできませんが、プロパティ「アクティブ」をシリアル化できる必要があります。
これは Object.create の使い方が間違っているのでしょうか? シリアライズ可能な「クラス」を作成し、シリアライズ可能な「インスタンス」を取得したいだけです。これどうやってするの?