File tree Expand file tree Collapse file tree 3 files changed +18
-1
lines changed Expand file tree Collapse file tree 3 files changed +18
-1
lines changed Original file line number Diff line number Diff line change @@ -6,4 +6,15 @@ function Singleton() {
6
6
Singleton . instance = this ;
7
7
}
8
8
9
+ // Usage
10
+
9
11
console . assert ( new Singleton ( ) === new Singleton ( ) ) ;
12
+ console . log ( 'instances are equal' ) ;
13
+
14
+ // But instance is accessible
15
+
16
+ const a1 = new Singleton ( ) ;
17
+ Singleton . instance = null ;
18
+ console . log ( 'Remove instance' ) ;
19
+ const a2 = new Singleton ( ) ;
20
+ if ( a1 !== a2 ) console . log ( 'a1 !== a2' ) ;
Original file line number Diff line number Diff line change @@ -5,4 +5,7 @@ const Singleton = new (function() {
5
5
return function ( ) { return single ; } ;
6
6
} ) ( ) ;
7
7
8
+ // Usage
9
+
8
10
console . assert ( new Singleton ( ) === new Singleton ( ) ) ;
11
+ console . log ( 'instances are equal' ) ;
Original file line number Diff line number Diff line change 1
1
'use strict' ;
2
2
3
- const Singleton = ( function ( ) {
3
+ const Singleton = ( ( ) => {
4
4
let instance ;
5
5
6
6
function Singleton ( ) {
@@ -13,4 +13,7 @@ const Singleton = (function() {
13
13
return Singleton ;
14
14
} ) ( ) ;
15
15
16
+ // Usage
17
+
16
18
console . assert ( new Singleton ( ) === new Singleton ( ) ) ;
19
+ console . log ( 'instances are equal' ) ;
You can’t perform that action at this time.
0 commit comments