Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 9635340

Browse filesBrowse files
committed
Upgrade usage examples
1 parent 61b9178 commit 9635340
Copy full SHA for 9635340

File tree

Expand file treeCollapse file tree

3 files changed

+18
-1
lines changed
Filter options
Expand file treeCollapse file tree

3 files changed

+18
-1
lines changed

‎JavaScript/1-simple.js

Copy file name to clipboardExpand all lines: JavaScript/1-simple.js
+11Lines 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

Copy file name to clipboardExpand all lines: JavaScript/2-safe.js
+3Lines 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

Copy file name to clipboardExpand all lines: JavaScript/3-complex.js
+4-1Lines 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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.