Advertisement
tonysamperi

008 - ES2022 static init

Aug 13th, 2022 (edited)
949
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
JavaScript 0.35 KB | Source Code | 0 0
  1. // ❌ BEFORE
  2. class Foo {
  3.   static fruits = ["Peach", "Orange", "Pear"];
  4.   static favouriteFruit;
  5.  
  6.   static init() {
  7.     this.favouriteFruit = this.fruits[0];
  8.   }
  9. }
  10.  
  11. Foo.init();
  12.  
  13. // ✅ ES2022
  14. class Foo {
  15.   static fruits = ["Peach", "Orange", "Pear"];
  16.   static favouriteFruit;
  17.  
  18.   static {
  19.     this.favouriteFruit = this.fruits[0];
  20.   }
  21. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement