(작성중)[생성패턴]싱글톤 패턴

K00·2023년 3월 6일
0
class Ins {
  static instance;
  constructor() {
    if (!Ins.instance) {
      Ins.instance = this;
      console.log(this);
    }
    return Ins.instance;
  }
}

let ins1 = new Ins();
let ins2 = new Ins();

if (ins1 === ins2) {
  console.log("same instance");
} else {
  console.log("not same instance");
}

0개의 댓글