|
|
|
|
|
by aboodman
619 days ago
|
|
Hello JS was my first language and I use classes because sometimes it seems like the obvious way to model things. Looking through the source of Replicache, here are some classes we use: - KVStore - DAGStore - Transaction I mean ... I can of course model these w/o classes, but encapsulating the state and methods together feels right to me. Especially when there is private state that only the methods should manipulate. We use composition all over the place and rarely use inheritance so I don't think it's just some deficiency of knowledge . Pre JS classes, the js community emulated classes w/ the prototype chain and that's what I'd have done for these classes if real JS classes weren't available. |
|
emulating classes is, imo, exactly the problem
using factory functions which create and return an object, with variables passed to and created in the function, handles encapsulation
and there is no `this` to deal with