function initState(vm, state) {
for (const key in state) {
vm.model[key] = state[key];
}
}
function initComputed(vm, computed) {
for (const key in computed) {
const userDef = _.bind(computed[key], vm);
vm.model[key] = userDef()
}
}
class Model {
constructor(model) {
this.model = {};
initState(this, model.state);
initComputed(this, model.computed);
}
}
let a = new Model({
state: {
a: "111"
},
computed: {
b: () => this.model.a + "2";
}
})
con