for singleton pattern, the problem is it does not hold values as 2 different instances of counter does... you can select a better example for this pattern.
as always thankyou for the videos brother, I found another possible implementation of singleton design pattern if that might help some of us: class Singleton{ constructor(){ if(Singleton.instance == null){ this.logs = []; Singleton.instance = this; } return Singleton.instance; } log(message){ this.logs.push(message) console.log("Logger logged: ", message); } printLogCount(){ console.log("Total Logs are: ", this.logs.length); } } const firstInstanceS = new Singleton(); const secondInstanceS = new Singleton(); console.log(firstInstanceS === secondInstanceS);
Make a playlist on design patterns in react,
Sure
Thankyou really useful.
for singleton pattern, the problem is it does not hold values as 2 different instances of counter does... you can select a better example for this pattern.
as always thankyou for the videos brother,
I found another possible implementation of singleton design pattern if that might help some of us:
class Singleton{
constructor(){
if(Singleton.instance == null){
this.logs = [];
Singleton.instance = this;
}
return Singleton.instance;
}
log(message){
this.logs.push(message)
console.log("Logger logged: ", message);
}
printLogCount(){
console.log("Total Logs are: ", this.logs.length);
}
}
const firstInstanceS = new Singleton();
const secondInstanceS = new Singleton();
console.log(firstInstanceS === secondInstanceS);
Thanks for the video 😌
You're welcome
Your website is down
Yes