We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent e367ae9 commit cd63c8aCopy full SHA for cd63c8a
JavaScript/1-simple.js
@@ -1,7 +1,7 @@
1
'use strict';
2
3
function Singleton() {
4
- const instance = Singleton.instance;
+ const { instance } = Singleton;
5
if (instance) return instance;
6
Singleton.instance = this;
7
}
JavaScript/3-complex.js
@@ -3,13 +3,13 @@
const Singleton = (() => {
let instance;
- function Singleton() {
- if (instance) return instance;
8
- instance = this;
+ class Singleton {
+ constructor() {
+ if (instance) return instance;
9
+ instance = this;
10
+ }
11
12
- Singleton.prototype.test = function() {};
-
13
return Singleton;
14
})();
15
0 commit comments