how to define a static property in the ES6 classes [duplicate]

安稳与你 提交于 2019-12-03 04:22:36

One way of doing it could be like this:

let _cards = [];
class Game{
    static get cards() { return _cards; }
}

Then you can do:

Game.cards.push(1);
console.log(Game.cards);

You can find some useful points in this discussion about including static properties in es6.

class Game{
   constructor(){}
}
Game.cards = [];

Game.cards.push(1);
console.log(Game.cards);

You can define a static variable like that.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!