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.
What is this garbage
OOP brainwashed
It's also very dated
this looks very outdated, i think the book is written pre ES6
yes. please suggest me better books
I would suggest not going for so many books, but YDKJS is probably a better book
it also is not recent though, right
YDKJS is frequently updated and online
i saw that 3rd edition is not avaliable yet, so that was my assumption. thank you
2nd edition was last updated 40 minutes ago
thank you very much, I was not aware.
Обсуждают сегодня