{"size": 1118, "ext": "js", "max_stars_repo_path": "Design_patterns/03-singleton.js", "max_stars_repo_name": "Danntastico/javascript-knowledge", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Design_patterns/03-singleton.js", "max_issues_repo_name": "Danntastico/javascript-knowledge", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Design_patterns/03-singleton.js", "max_forks_repo_name": "Danntastico/javascript-knowledge", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 19.275862069, "max_line_length": 50, "alphanum_fraction": 0.6305903399}
//Crating just ONE instance of a class

//On JS could have multiple Forms

//1. Simple Object literal grouped together
var mySingleton = {
  prop1: 'Hello World',
  prop2: 'From Colombia',
  prop3: () => console.log('other properties'),
};

//2.Encapsulating var and fnc inside a closure

let SingletonClos = () => {
  let privateVariable = 'private';
  let showPrivate = () => {
    console.log(privateVariable);
  };

  return {
    publicMethod: () => showPrivate(),
    publicVariable: 'public',
  };
};

let singletonClosure = SingletonClos();
/* 
console.log(singletonClosure.publicMethod());
console.log(singletonClosure.publicVariable);
 */
//Instantiate the singleton when its needed.

var Singleton3 = (function () {
  var fncInstance;

  function init() {
    return {
      publicMethod: function () {
        console.log('Hi there!');
      },
      publicValue: 'You guys can see me',
    };
  }

  return {
    getInstance: () => {
      if (!fncInstance) {
        fncInstance = init();
      }
      return fncInstance;
    },
  };
})();

console.log(Singleton3.getInstance().publicValue);

//Page 26
