Похожие чаты

The idea of the singleton pattern is to have only

one instance of a specific class. This
means that the second time you use the same class to create a new object, you should
get the same object that was created the first time.
And how does this apply to JavaScript? In JavaScript there are no classes, just objects.
When you create a new object, there’s actually no other object like it, and the new
object is already a singleton. Creating a simple object using the object literal is also an
example of a singleton:
var obj = {
myprop: 'my value'
};
In JavaScript, objects are never equal unless they are the same object, so even if you
create an identical object with the exact same members, it won’t be the same as the first
one:
var obj2 = {
myprop: 'my value'
};
obj === obj2; // false
obj == obj2; // false
So you can say that every time you create an object using the object literal, you’re
actually creating a singleton, and there’s no special syntax involved.

11 ответов

8 просмотров

OOP brainwashed

It's also very dated

this looks very outdated, i think the book is written pre ES6

Emre- Автор вопроса

I would suggest not going for so many books, but YDKJS is probably a better book

Emre- Автор вопроса
Emre
it also is not recent though, right

YDKJS is frequently updated and online

Emre- Автор вопроса
Thomas
YDKJS is frequently updated and online

i saw that 3rd edition is not avaliable yet, so that was my assumption. thank you

Emre
i saw that 3rd edition is not avaliable yet, so th...

2nd edition was last updated 40 minutes ago

Emre- Автор вопроса
Thomas
2nd edition was last updated 40 minutes ago

thank you very much, I was not aware.

Похожие вопросы

Обсуждают сегодня

я не магистр хаскеля, но разве не может лейзи тип конвертнуться в не-лейзи запросив вычисление содержимого прям при инициализации?
deadgnom32 λ madao
49
30 BCH videos in Hausa Language successfully delivered. In December 2023, I created a Flipstarter to produce Bitcoin Cash videos in the Hausa language for greater outreach an...
Munnir
5
читать файл максимально быстро? странный вопрос))
zamtmn
53
Интересно, а майкрософт 365 может запустится на линукс минт?
Лисицка
17
How to create an OS in C? what to study?
Linus
18
Компания Elif ищет менеджера проектов, который будет заниматься поиском и ведением новых проектов. Прежде чем приступить к работе, вам нужно пройти наш недельный курс, где вы ...
Elif
5
братва! где куличи брать?
Alöscha
25
Привет, кто может сделать юзербота с апи? Задачи: - создавать группы - создавать каналы - задавать для созданных каналов аватарку или эмоджи, имя группы - добавлять в группы...
Lencore
11
на сколько можно увеличить swap при 16Гб оперативы?
Хасан Ахмаев
11
тоесть, указав return eax, сгенерируется никому ненужная инструкция mov eax,eax ?
Aiwan \ (•◡•) / _bot
24
Карта сайта