Answers for "Private slots are new and can be created via Static initialisation blocks in classes"

0

Private slots are new and can be created via Static initialisation blocks in classes

class Translator {
  static translations = {
    yes: 'ja',
    no: 'nein',
    maybe: 'vielleicht',
  };
  static englishWords = [];
  static germanWords = [];
  static { // (A)
    for (const [english, german] of Object.entries(this.translations)) {
      this.englishWords.push(english);
      this.germanWords.push(german);
    }
  }
}


console.log(Translator.englishWords, Translator.germanWords)
//Output -> ["yes", "no", "maybe"], ["ja", "nein", "vielleicht"]
Posted by: Guest on March-25-2022

Code answers related to "Private slots are new and can be created via Static initialisation blocks in classes"

Code answers related to "Javascript"

Browse Popular Code Answers by Language