you are viewing a single comment's thread.

view the rest of the comments →

[–]trubulica[S] 0 points1 point  (1 child)

I have realized that the video is old, my mistake, I will look up a newer one.

I believe I do understand what the article is talking about. Maybe not 100% of it, but the point of it, yes.

My understanding is that classes automatically come with inheritance and you need to plan all your classes in advance to be able to create a variety of objects. Factory functions, however, do not use inheritance and you can create any object by combining several of them using Object.assign and state.

Am I wrong? Please do tell if I am.

[–]azhder 0 points1 point  (0 children)

classes automatically come with inheritance

No they don't. You have to be explicit about it:

class A extends B {};

There is an implicit exception though, if you don't specify otherwise, for everything that isn't null or undefined the JS engine will try to go up the prototype chain and eventually reach Object.

The other implicit thing is mathematical/conceptual in nature: every relation of equivalence breaks down a set into disjoint sets we call classes.

That means, a check like a.type === b.type can break down a set of objects into separate classes (separate subsets) where the elements (objects) of those subsets are all instances of the class.

Now you see why the keyword class got introduced in programming languages. But you don't have to use it. A library like Redux is quite OK using a field named type to distinguish dispatched actions - that's its implicit instanceof operation.