News for hackers. Stuff that matters.
Re:Replacing ‘that = this’ assignments in JavaScript with Ar... by andrewstuart2 on Friday April 14, 2017 @03:00PM (#14116368)
The main reason I've come to avoid prototypes in many cases (except when I really need to control memory) is that you can't keep any kind of information private (via closure) and share it across instance methods. It has to be a property on the instance, and is therefore accessible to anybody with access to the instance.

Conventions (like prefixing with _) are great, but they can only help loosely enforce encapsulation and provide no form of real privacy.

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.

https://www.youtube.com/watch?v=ImwrezYhw4w

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.