为 class 设置初始值
set initial values for class
这是我的 class
export default class Store extends Parse.Object {
constructor() {
super('Store');
this.product = [];
}
}
导入后我这样做
let store = new Store();
但问题是产品的价值没有被初始化,它仍然是未定义的。
有什么解决这个问题的想法吗?
我不想在创建实例后进行初始化,就像这样
store.set('product', []);
已找到解决方案,下面是它的工作原理
export default class Store extends Parse.Object {
constructor() {
super('Store');
this.set('product', []);
}
}
但是文档显示如下,这是行不通的!
class Monster extends Parse.Object {
constructor() {
// Pass the ClassName to the Parse.Object constructor
super('Monster');
// All other initialization
this.sound = 'Rawr';
}
}
这是我的 class
export default class Store extends Parse.Object {
constructor() {
super('Store');
this.product = [];
}
}
导入后我这样做
let store = new Store();
但问题是产品的价值没有被初始化,它仍然是未定义的。
有什么解决这个问题的想法吗? 我不想在创建实例后进行初始化,就像这样
store.set('product', []);
已找到解决方案,下面是它的工作原理
export default class Store extends Parse.Object {
constructor() {
super('Store');
this.set('product', []);
}
}
但是文档显示如下,这是行不通的!
class Monster extends Parse.Object {
constructor() {
// Pass the ClassName to the Parse.Object constructor
super('Monster');
// All other initialization
this.sound = 'Rawr';
}
}