There is such a small piece of code:
if (Rect.__instances__) { Rect.__instances__.push(this); } else { Rect.__instances__ = []; Rect.__instances__ = [].push(this); } Essence: if the class has a property __instances__ , then we push this into it. If not, then we first initialize __instances__ an empty array, and then we push this into it.
We need to write this condition in one line of the form:
Rect.__instances__ ? Rect.__instances__.push(this) : Rect.__instances__ = [].push(this); But this code, instead of returning an array with the value of this inside, simply returns one.
Then I tried to do this:
Rect.__instances__ ? Rect.__instances__.push(this) : Rect.__instances__ = (() => {return []}).push(this); To which I gave an error of the form:
Uncaught TypeError: (intermediate value) .push is not a function
Tried it like this:
Rect.__instances__ ? Rect.__instances__.push(this) : Rect.__instances__ = (() => {new Array()}).push(this); The error is the same.
Now I ask for help here. By the way, if someone understood what this code is doing and for what I am writing there is a better solution, like standard library methods, then this approach will also fit :)
PS I added the lambda tag to the question, because here, it seems to be how it comes to this. The fact is that lambda in javascript I googled, and in response I was given only infu associated with the pointer f-mi. Therefore, I ventured to assume that since the matter is most likely in the switch function, then the lambda tag fits here.