8000 Closure singletom example · HowProgrammingWorks/Singleton@b422272 · GitHub
[go: up one dir, main page]

Skip to content

Commit b422272

Browse files
committed
Closure singletom example
1 parent 9635340 commit b422272

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

JavaScript/4-closure.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
'use strict';
2+
3+
const singleton = (() => {
4+
const instance = {};
5+
return () => instance;
6+
})();
7+
8+
// Usage
9+
10+
console.assert(singleton() === singleton());
11+
console.log('instances are equal', singleton());

0 commit comments

Comments
 (0)
0