Very neat article with inspiring code. I never thought of your "private class member" with symbols, this is amazing (Why use Symbol.for tho ? It would allow access with instance[Symbol.for("name")] ?!.
Another question, why use Map for the classes dictionary ? Object literal would make a more readable code (IMO of course).
Actually, yeah, you're right... I should've used Symbol('name') instead. My bad! I'll fix the examples.
In the case of the classes lookup, you might have to have some mapping between the value of the $type property and the actual classname if they happen to not coincide. But really, there's no reason to pick Map over an object if you're just mapping strings to objects. I just like to use Map instead of POJOs as hashmaps when they become highly polymorphic, as it doesn't create hidden classes on mutation.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Very neat article with inspiring code. I never thought of your "private class member" with symbols, this is amazing (Why use
Symbol.for
tho ? It would allow access withinstance[Symbol.for("name")]
?!.Another question, why use
Map
for the classes dictionary ? Object literal would make a more readable code (IMO of course).Actually, yeah, you're right... I should've used
Symbol('name')
instead. My bad! I'll fix the examples.In the case of the classes lookup, you might have to have some mapping between the value of the
$type
property and the actual classname if they happen to not coincide. But really, there's no reason to pickMap
over an object if you're just mapping strings to objects. I just like to useMap
instead of POJOs as hashmaps when they become highly polymorphic, as it doesn't create hidden classes on mutation.