Last active
July 3, 2019 09:12
-
-
Save kshitijpurwar/c167f80d78c8420c2a739da9dcd091d0 to your computer and use it in GitHub Desktop.
Fake Singleton with Node
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Dog { | |
constructor(name = "default") { | |
this.name = name; | |
console.log("My name is ", name); | |
} | |
} | |
module.exports = Dog; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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