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() {
66 Singleton . instance = this ;
77}
88
9+ // Usage
10+
911console . 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() {
55 return function ( ) { return single ; } ;
66} ) ( ) ;
77
8+ // Usage
9+
810console . assert ( new Singleton ( ) === new Singleton ( ) ) ;
11+ console . log ( 'instances are equal' ) ;
Original file line number Diff line number Diff line change 11'use strict' ;
22
3- const Singleton = ( function ( ) {
3+ const Singleton = ( ( ) => {
44 let instance ;
55
66 function Singleton ( ) {
@@ -13,4 +13,7 @@ const Singleton = (function() {
1313 return Singleton ;
1414} ) ( ) ;
1515
16+ // Usage
17+
1618console . assert ( new Singleton ( ) === new Singleton ( ) ) ;
19+ console . log ( 'instances are equal' ) ;
You can’t perform that action at this time.
0 commit comments