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
29 changes: 13 additions & 16 deletions content/en/tags-hideconstructor.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,36 +77,33 @@ var Toaster = (function() {
* Waffle iron singleton.
*/
class WaffleIron {
#instance = null;
static #isUsingSingletonFactoryMethod = false;
static #instance = null;

/**
* Create the waffle iron.
*
* @hideconstructor
*/
constructor() {
if (#instance) {
return #instance;
}

/**
* Cook a waffle.
*
* @param {Batter} batter - The waffle batter.
* @return {Waffle} The cooked waffle.
*/
this.cook = function(batter) {};

this.#instance = this;
// The constructor should never be called directly.
if (!WaffleIron.#isUsingSingletonFactoryMethod) {
throw new Error('WaffleIron is a singleton. Please use its getInstance() method to get a reference to it.')
}
}

/**
* Get the WaffleIron instance.
*
* @return {WaffleIron} The WaffleIron instance.
*/
getInstance() {
return new WaffleIron();
static getInstance() {
if (this.#instance === null) {
this.#isUsingSingletonFactoryMethod = true;
this.#instance = new WaffleIron();
this.#isUsingSingletonFactoryMethod = false;
}
return this.#instance;
}
}
```
Expand Down