Skip to content Skip to sidebar Skip to footer

Es6: Super Class Doesn't Hold State

I'm trying to figure out what's going on here, as the Parent/Super class does not have data after the initial construction. // imports/server/a-and-b.js class A { constructor(id)

Solution 1:

This is what I found:

classA{
  constructor(id) {
    // make MongoDB call and store inside this variable// ...this._LocalVariable = FieldFromMongo;
  }
  get LocalVar() {
    returnthis._LocalVariable;
  }
  GetThatLocalVar() {
    returnthis._LocalVariable;
  }
}

export classBextendsA{
  constructor(id) {
    super(id);
  }
  get Style1() {
    // Reference to Parent get functionreturnsuper.LocalVar; // => This has a undefined value when called
  }
  get Style2() {
    // Reference to Parent propertyreturnsuper._LocalVariable; // => This has a undefined value when called
  }
  get Style3() {
    // Reference to local Property that is declared in Parentreturnthis._LocalVariable; // => This works
  }
  get Style4() {
    // Reference to Parent without the getterreturnsuper.GetThatLocalVar(); // => This works
  }
  get GETTHEVAR() {
    returnthis.TEST; // => This returns 'THIS IS A TEST'
  }
}

So basically the thing that works is Style3 Style 4 work.

Post a Comment for "Es6: Super Class Doesn't Hold State"