S
S
Stepan2015-09-14 00:55:10
JavaScript
Stepan, 2015-09-14 00:55:10

How to create a static variable in ES6?

How to set a variable in a class.
static is not suggested.

SubList.style = {
        overflow: 'hidden'
    };
//Не работает 

    SubList.prototype.style = {
        overflow: 'hidden'
    };

Can be defined in the constructor?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
K
Konstantin Kitmanov, 2015-09-14
@k12th

No, ES6 doesn't have that. But in ES7 it is planned , babel supports it.

S
Sergey, 2015-09-14
Protko @Fesor

Can be defined in the constructor?

you wanted static. Otherwise:
class SubList {
    get style() {
        return {
              overflow: 'hidden'
        };
    }
}

it is possible to stir up a statics also, but then it will be necessary to address also through SubList.
updated:
var someObj = {
    overflow: 'hidden'
};

export default class FooBar {
    get someObj() {
         return someObj;
    }
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question