NEWS
zuweisen von this innerhalb objekten
-
Hallo,
@Marc-Berg hatte mir ja schon einmal mitgeteilt, dass man this nur innerhalb einer function und nicht einer arrowfunction nutzen kann.
nun habe ich folgendes "Problem":
const partymodus = { id: "alias.0.Garten.Rasenbotober.partyModus", state: null, automaticVal: null, setAutomaticVal: function (automaticVal){ // Zuweisen nur bei Änderung des Automatikvalues if(automaticVal !== this.automaticVal){ partymodus.automaticVal = automaticVal; // Zusätzlich nur schreiben, wenn der Partymodus nicht bereits auf dem gewünschten Wert steht if(this.automaticVal !== this.state.val){ setState(partymodus.id,partymodus.automaticVal); } } } }
funktioniert !!!.
Ändere ich nur die zuweisung des automaticval um:
const partymodus = { id: "alias.0.Garten.Rasenbotober.partyModus", state: null, automaticVal: null, setAutomaticVal: function (automaticVal){ // Zuweisen nur bei Änderung des Automatikvalues if(automaticVal !== this.automaticVal){ this.automaticVal = automaticVal; // Zusätzlich nur schreiben, wenn der Partymodus nicht bereits auf dem gewünschten Wert steht if(this.automaticVal !== this.state.val){ setState(partymodus.id,partymodus.automaticVal); } } } }
dann erscheint in der vorletzten Zeile:
Property 'state' does not exist on type 'setAutomaticVal'.(2339)
Obwohl ja nicht auf setAutomaticVal zugegriffen wird, sondern darin befindet sich ja der code.