If I don't want to initialize all properties of a class when it is instantiated in Java it can be done like this:
class Example {
Example(int property1){
this.setProperty1(property1);
}
int property1;
int property2;
getProperty1(){
return this.property1;
}
setProperty1(int property1){
this.property1 = property1;
}
getProperty2(){
return this.property2;
}
setProperty1(int property2){
this.property2 = property2;
}
}
In this case I don't want to initialize right away property2
when I instantiate the Example
class.
My question is how can I achieve the same behavior using JS classes, because in my case the following is not working, I can't set values to the chaveDeAcesso
property:
(BTW: I'm using ESLint with the Airbnb style-guide on vscode)
class NotaFiscal {
constructor(indexNotaFiscal) {
this.indexNotaFiscal = indexNotaFiscal;
}
chaveDeAcesso;
get chaveDeAcesso() {
return this.chaveDeAcesso;
}
set chaveDeAcesso(chaveAcesso) {
this.chaveDeAcesso = chaveAcesso;
}
}