File tree Expand file tree Collapse file tree 3 files changed +33
-0
lines changed Expand file tree Collapse file tree 3 files changed +33
-0
lines changed Original file line number Diff line number Diff line change
1
+ 'use strict' ;
2
+
3
+ function Singleton ( ) {
4
+ const instance = Singleton . instance ;
5
+ if ( instance ) return instance ;
6
+ Singleton . instance = this ;
7
+ }
8
+
9
+ console . assert ( new Singleton ( ) === new Singleton ( ) ) ;
Original file line number Diff line number Diff line change
1
+ 'use strict' ;
2
+
3
+ const Singleton = new ( function ( ) {
4
+ const single = this ;
5
+ return function ( ) { return single ; } ;
6
+ } ) ( ) ;
7
+
8
+ console . assert ( new Singleton ( ) === new Singleton ( ) ) ;
Original file line number Diff line number Diff line change
1
+ 'use strict' ;
2
+
3
+ const Singleton = ( function ( ) {
4
+ let instance ;
5
+
6
+ function Singleton ( ) {
7
+ if ( instance ) return instance ;
8
+ instance = this ;
9
+ }
10
+
11
+ Singleton . prototype . test = function ( ) { } ;
12
+
13
+ return Singleton ;
14
+ } ) ( ) ;
15
+
16
+ console . assert ( new Singleton ( ) === new Singleton ( ) ) ;
You can’t perform that action at this time.
0 commit comments