I have an object like
var Profile = Object.create(null);
Object.defineProperties(Profile, {
id: {
value: "",
enumerable: true
},
name: {
value: "",
enumerable: true
},
active: {
value: true,
enumerable: true
}
});
Now I want to create an Profile instance and give it id and name, and keep active default true, so I do this:
var p1 = Object.create(Profile, {
id: {
value: "123",
enumerable: true
},
name: {
value: "hello world",
enumerable: true
}
});
Then I got an object named p1, but I cannot find "active" in
Object.getOwnPropertyNames(p1);
Also I cannot use JSON.stringify(p1) to serialize property "active", but I need property "active" can be serializable.
Is this the wrong way I used Object.create? I just want to create a serializable "class" and get it's serializable "instance". How can I do this?