Live data from Hacker News

Public and private class fields

developers.google.com

111–112 of 112 posts

Re: Public and private class fields

#111

Earlier quoted context omitted.

what i was demonstrating by showing that design pattern is that there is already an easier and clean way to do private variables and scopes. BUT if you want to talk about its speed and efficiency here we go: It very intentionally trades memory space for faster variable resolution. plz read this article - https://www.toptal.com/javascript/javascript-prototypes-scop... he has some test code at the end that compares the…

Bear in mind, in the cases you refer to, the inner functions should only be allocated once - when the file is loaded. The issue is when you use this pattern for initialising what are effectively classes. Then every time you use `new`, the functions have to be wrapped again.

Again you are saying the "inner functions should only be allocated once", there is no rule or book in CS that states that as the absolute truth. It is however a concept that would be taught in a typical OO programming class.

Idk where exactly you were taught this, or if you did not read my whole speil about that being memory/cpu tradeoff.

i know i put up a wall of text, but if u have time to read one article on JS from all of this it is this article - https://medium.com/javascript-scene/common-misconceptions-ab...

Re: Public and private class fields

#112
post #5

This is Exhibit N for the "the class keyword is ruining Javascript" prosecution. If you want a "private variable" you just use a closure. let incrementer = () => { let x = 0; return { value: () => x, increment: () => x++ }; }; It's like the OO people are determined to forget about the functional concepts that made JS great.

But, that's so much more complicated then just having a private variable.
Post reply on HN