So I've read around stackoverflow. In ES6 this is invalid:
class MyClass {
myProperty = "";
constructor() {
this.myProperty = "Hey";
}
}
But it is valid in ES7.
However, is this valid:
class MyClass {
setViewModel(viewModel) {
this.internalViewModel = viewModel;
}
get viewModel() { return this.internalViewModel }
}
Here I haven't defined internalViewModel
until I've actually set it. I expect that if you haven't called myClass.setViewModel(something)
before you call myClass.viewModel
, you will get undefined
returned from myClass.viewModel
.
Is this correct?
If you have this ES7 class and you tried to access myProperty
like so myClass.myProperty
would you get the expected "Hey"
or not?