set initial values for class

时间:2017-06-15 09:35:58

标签: javascript parse-server

here is my class

export default class Store extends Parse.Object {
    constructor() {
        super('Store');

        this.product = [];
    }
}

and after importing it I do this

let store = new Store();

but the issue is the value of product is not initialized, it is still undefined.

any ideas how to solve this issue? I dont want to initialize after I create the instance, like this

store.set('product', []);

1 个答案:

答案 0 :(得分:2)

Found a solution, here is how it will work

export default class Store extends Parse.Object {
    constructor() {
        super('Store');

        this.set('product', []);
    }
}

but the docs shows as bellow, which is not working !

class Monster extends Parse.Object {
  constructor() {
    // Pass the ClassName to the Parse.Object constructor
    super('Monster');
    // All other initialization
    this.sound = 'Rawr';
  }

}