JavaScript ES6の基本的な文法と、Singleton(シングルトン)パターンの実装についてのメモです。
 🎂 クラス
'use strict';
  class Person {   constructor() {     this.data1 = 1;   }
    getData1() {     return this.data1;   } }
   | 
 
🗻 クラスの継承について
ES6ではクラス構造を継承できるようになりました。
'use strict'
 
  class SuperTest {   constructor() {     this.name = 'Super';   }
    sayName() {     return this.name;   } }
 
  class SubTest extends SuperTest {      constructor() {     super();     this.name = 'Sub'   }
    sayName() {      return super.sayName() + 'のサブクラス';   }
    sayHello() {      console.log('Hello!!');   } }
  const test1 = new SuperTest; const test2 = new SubTest;
  console.log(test1.sayName());  console.log(test2.sayName());  test2.sayHello(); 
   | 
 
👽 シングルトンパターン
userStoreInstanceを処理で使うことでシングルトンとして使えるようにします。
class UserStore {   constructor(){     this._data = [];   }
    add(item){     this._data.push(item);   }
    get(id){     return this._data.find(d => d.id === id);   } }
  const userStoreInstance = new UserStore();
 
  Object.freeze(instance);
  export default userStoreInstance;
  | 
 
🍣 参考リンク
                
    
    
    
    
                
    🖥 VULTRおすすめ
    
      「VULTR」はVPSサーバのサービスです。日本にリージョンがあり、最安は512MBで2.5ドル/月($0.004/時間)で借りることができます。4GBメモリでも月20ドルです。
      最近はVULTRのヘビーユーザーになので、「ここ」から会員登録してもらえるとサービス開発が捗ります!