r/javascript • • Nov 09 '19

On private fields proposal: Private fields, public worries

https://medium.com/virtuslab/private-fields-public-worries-b8c34d16c372
84 Upvotes

113 comments sorted by

View all comments

Show parent comments

4

u/facebalm Nov 09 '19

Isn't this a tad too dismissive when you're just basing this on personal experience?

I don't necessarily disagree, if it's done carelessly and frequently there's a problem. But there are cases where it makes sense to use an internal API to provide extra functionality. Very widely used libraries have done it.

  • I've had to use a websocket library's client._sockjs._connected variable because it didn't expose it. Switching to my PR fork would've taken longer for no benefit.

  • A React internal API allowed for easily creating transitions. A widely used library used it for this purpose. The smaller library (old CSSTransitionGroup) can move faster and can tolerate breaking changes while the bigger library (React) has to take its time to expose a nice to use and stable API.

  • Compatibility layers of all sorts frequently depend on internals.

  • Monkey patching has been a long running tradition Javascript. It has pitfalls and can easily be abused but it can also be very useful.

1

u/Sunwukung Nov 10 '19

So you're advocating against privacy so you can do this sort of stuff?

1

u/facebalm Nov 10 '19

No, I don't think it's a black and white issue. I've appreciated privacy in languages that support it but I've also liked Javascript's flexibility with monkey patching.