File tree Expand file tree Collapse file tree 2 files changed +32
-14
lines changed
Expand file tree Collapse file tree 2 files changed +32
-14
lines changed Original file line number Diff line number Diff line change 1+ /// <reference path="singleton.ts" />
2+ namespace SingletonPattern {
3+ export namespace Demo {
4+
5+ export function show ( ) : void {
6+ var singleton1 = SingletonPattern . Singleton . Instance ;
7+ var singleton2 = SingletonPattern . Singleton . Instance ;
8+
9+ if ( singleton1 === singleton2 ) {
10+ console . log ( "two singletons are equivalent" ) ;
11+ } else {
12+ console . log ( "two singletons are not equivalent" ) ;
13+ }
14+ }
15+ }
16+ }
17+
18+ SingletonPattern . Demo . show ( ) ;
Original file line number Diff line number Diff line change 1- namespace SingletonPattern {
2- export class Singleton {
3- private static instance : Singleton ;
4-
5- constructor ( ) { }
6-
7- static get Instance ( ) {
8- if ( this . instance === null || this . instance === undefined ) {
9- this . instance = new Singleton ( ) ;
10- }
11- return this . instance ;
12- }
13- }
14- }
1+ namespace SingletonPattern {
2+ export class Singleton {
3+ private static instance : Singleton ;
4+
5+ constructor ( ) { }
6+
7+ static get Instance ( ) {
8+ if ( this . instance === null || this . instance === undefined ) {
9+ this . instance = new Singleton ( ) ;
10+ }
11+ return this . instance ;
12+ }
13+ }
14+ }
You can’t perform that action at this time.
0 commit comments