Private Names in 'text/javascript'

Erik Corry erik.corry at gmail.com
Wed May 18 02:46:12 PDT 2011


2011/5/18 Luke Hoban <lukeh at microsoft.com>:
> The Private Names strawman currently combines a new runtime capability
> (using both strings and private names as keys in objects) with several new
> syntactic constructs (private binding declarations, #.id).  At the March
> meeting, I recall there was some support for the idea of separating these
> two aspects, and exposing the runtime capability also as a library that
> could be used in ‘text/javascript’.
>

I'd like to support this idea.

Your example looks a bit wrong to me though.  It seems to make new
private names per object.  Surely we want a private name per 'class'
instead.

var Point = (function() {
  var _x = Object.createPrivateName();
  var _y = Object.createPrivateName();

  var Point = function(x, y) {
    this[_x] = x;
    this[_y] = y;
  }

  Point.prototype.myMethodUsing_xAnd_y = function() {...}

  return Point;
})()


var p = new Point(1, 2);

-- 
Erik Corry


More information about the es-discuss mailing list