Skip to content

Commit 9635340

Browse files
committed
Upgrade usage examples
1 parent 61b9178 commit 9635340

File tree

3 files changed

+18
-1
lines changed

3 files changed

+18
-1
lines changed

JavaScript/1-simple.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,15 @@ function Singleton() {
66
Singleton.instance = this;
77
}
88

9+
// Usage
10+
911
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');

JavaScript/2-safe.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,7 @@ const Singleton = new (function() {
55
return function() { return single; };
66
})();
77

8+
// Usage
9+
810
console.assert(new Singleton() === new Singleton());
11+
console.log('instances are equal');

JavaScript/3-complex.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
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+
1618
console.assert(new Singleton() === new Singleton());
19+
console.log('instances are equal');

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy