Closed Ravenex closed 5 years ago
Hello,
No need for a new method, all you need is Object.assign
const PersonModel = ObjectModel({ name: String, _gender: [String] })
class Person extends PersonModel {
loadDynamicProps(propGroup) {
const propList = {
sport: String,
food: [String],
number: Number,
_color: [String]
}
Object.assign(PersonModel.definition, propList)
}
}
const Joe = new Person({ name: "Joe", _gender: "male" })
Joe.loadDynamicProps("favorites")
If you also want to set the value of these properties, assign to this:
Object.assign(this, {
sport: "Baseball",
number: 42,
_color: "Blue"
})
Note that you should probably declare this loadDynamicProps method in your model (PersonModel.loadDynamicProps) instead of in your instance. It's a bit weird that an instance is able to change its own model.
Thank you so much, I was not clear where or how to do that. This will work fine thanks.
I would like to request a method to define new properties of an object or class outside of the existing definition method by passing a properties object. This would be very useful in using ObjectModel in a dynamic way. For example: