Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions pages/patterns/design-patterns/singleton-pattern.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@ let instance;
class Counter {
constructor() {
if (instance) {
throw new Error("You can only create one instance!");
return instance;
}
this.counter = counter;
this.counter = 0;
instance = this;
}

Expand All @@ -72,7 +72,7 @@ class Counter {

// 2. Setting a variable equal to the the frozen newly instantiated object, by using the built-in `Object.freeze` method.
// This ensures that the newly created instance is not modifiable.
const singletonCounter = Object.freeze(new Counter());
const singletonCounter = new Counter();

// 3. Exporting the variable as the `default` value within the file to make it globally accessible.
export default singletonCounter;
Expand Down