Class literals: does "public" still make sense?

Axel Rauschmayer axel at rauschma.de
Sat Sep 24 16:17:59 PDT 2011


Without private members, do we still need the keyword "public" in class literals?

For example, instead of
  constructor(geometry, materials) {
    super(geometry, materials);
 
    public identityMatrix = new THREE.Matrix4();
    public bones = [];
    public boneMatrices = [];
    ...
  }
I find the following just as intuitive, without the need for the keyword "public":
  constructor(geometry, materials) {
    super(geometry, materials);
 
    this.identityMatrix = new THREE.Matrix4();
    this.bones = [];
    this.boneMatrices = [];
    ...
  }

Similarly intuitive is something that I’ve seen somewhere – passing through constructor arguments as members.
  class Point {
    constructor(this.x, this.y) {
    }
  }

I don’t think "public" helps, I think it makes things *less* intuitive.

-- 
Dr. Axel Rauschmayer

axel at rauschma.de
twitter.com/rauschma

home: rauschma.de
blog: 2ality.com





More information about the es-discuss mailing list