Re:Replacing ‘that = this’ assignments in JavaScript with Ar...
by learc83 on Friday April 14, 2017 @04:09PM
(#14116887)
I just use factory functions that return an object that has arrow functions as properties, then I get private information via closures, and I don't have to worry about dealing with this.
Re:Replacing ‘that = this’ assignments in JavaScript with Ar...
by WorldMaker on Friday April 14, 2017 @03:06PM
(#14116419)
You can combine the two, creating a closure for private variables and using proper prototypes. The easiest way now is the ES2015 class keyword and its syntax, but for older versions of JS there are patterns and practices (and about a zillion helper libraries) to do so.
Conventions (like prefixing with _) are great, but they can only help loosely enforce encapsulation and provide no form of real privacy.