ES6 und variabler Bereich innerhalb eines Versprechens

Nicht sicher, was ich hier vermisse.

Ich muss die Ausgabe von @ erhaltdatainthis.contact. Im Moment verwende ich eine statische Klassenvariable, aber es scheint schmutzig, das tun zu müssen.

export class contactEdit {
  static t; // static class var
  constructor() {
    this.id = null;
    this.contact = null;
    contactEdit.t = this;
  }

  activate(id) {
    this.id = id;
    let contact = this.contact; // scoped version of class var
    return dpd.contacts.get(id).then(function(data) {
      console.log(data);
      contactEdit.t.contact = data; // this works
      contact = data; // this doesn't
    });
  }
}

ormalerweise würde ich ein @ erstellvar contact innerhalb desactivate() -Funktion (funktioniert in der Chrome-Konsole), scheint aber in ES6 nicht zu funktionieren.

Chrome-Konsole:

var c = null;
undefined
c;
null
dpd.contacts.get('a415fdc8f5a7184d').then(function(data) {
      c = data;
    });
Object {}fail: (n)then: (e,t)__proto__: Object
c;
Object {firstName: "John", lastName: "Doe", id: "a415fdc8f5a7184d"}

Antworten auf die Frage(4)

Ihre Antwort auf die Frage