Navigation

    Logo
    • Register
    • Login
    • Search
    • Recent
    • Tags
    • Unread
    • Categories
    • Unreplied
    • Popular
    • GitHub
    • Docu
    • Hilfe
    1. Home
    2. Deutsch
    3. Skripten / Logik
    4. JavaScript
    5. zuweisen von this innerhalb objekten

    NEWS

    • Neuer Blog: Fotos und Eindrücke aus Solingen

    • ioBroker@Smart Living Forum Solingen, 14.06. - Agenda added

    • ioBroker goes Matter ... Matter Adapter in Stable

    zuweisen von this innerhalb objekten

    This topic has been deleted. Only users with topic management privileges can see it.
    • Ben1983
      Ben1983 last edited by Ben1983

      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.

      1 Reply Last reply Reply Quote 0
      • First post
        Last post

      Support us

      ioBroker
      Community Adapters
      Donate

      942
      Online

      31.9k
      Users

      80.2k
      Topics

      1.3m
      Posts

      1
      1
      65
      Loading More Posts
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes
      Reply
      • Reply as topic
      Log in to reply
      Community
      Impressum | Datenschutz-Bestimmungen | Nutzungsbedingungen
      The ioBroker Community 2014-2023
      logo