es-discuss Digest, Vol 46, Issue 22

thaddee yann tyl thaddee.tyl at
Fri Dec 24 09:59:23 PST 2010

I understand your point, but I am deeply disturbed by the fact that
this syntax modifies all |obj.secret| and |obj[secret]| and
|{secret:value}| within the scope of |private secret;|, including
those that we may not think about.

The following "private obj.secret;" syntax complies with your
non-sigil request, and it addresses all the issues I have met:

function Point(x, y) {
    private this.x, this.y;  // This private statement only has an
influence upon "this".
    this.x = x;
    this.y = y;
    // do stuff...
    return [#.x, #.y];

It defines precisely what object has a private name up front, thus
avoiding accidents such as:
var letters = {};
function Point(x, y) {
  private x, y;  // We want this.x and this.y to be private.
  this.x = x;
  this.y = y;
  // ... later that evening...
  letters.x = 'X';
  letters.y = 'Y';  // Oops, these weren't meant to be private names!

ps. Merry christmas.

More information about the es-discuss mailing list