我有两个课
export class Model {
_id: ID
constructor(arg : ID | string | Object) {
if (typeof arg === 'object') this.loadObject
}
loadObject(obj: Object) {
Object.assign(this, obj)
// using a for loop to assign keys does not work with flow
}
}
export class User extends Model {
_id: ID
username: string
//...other properties
}
当我调用new Model(userObject)
时,所有属性都已定义。但是,当我调用new User(userObject)
时,仅定义了一些属性,而有些则未定义。为什么会发生这种情况,我该如何解决?