Skip to content

Instantly share code, notes, and snippets.

@kshitijpurwar
Last active July 3, 2019 09:12
Show Gist options
  • Save kshitijpurwar/c167f80d78c8420c2a739da9dcd091d0 to your computer and use it in GitHub Desktop.
Save kshitijpurwar/c167f80d78c8420c2a739da9dcd091d0 to your computer and use it in GitHub Desktop.
Fake Singleton with Node
class Dog {
constructor(name = "default") {
this.name = name;
console.log("My name is ", name);
}
}
module.exports = Dog;
const Dog = require("./class");
const coco = new Dog("Coco");
const lola = new Dog("Lola");
console.log(coco);
console.log(lola);
const s1 = require("./singleton");
const s2 = require("./singleton");
require("./singleton");
console.log(s1);
console.log(s2);
console.log(s1 === s2);
const Dog = require("./class");
module.exports = new Dog();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment