Some questions about Private Name Objects

Matthew Robb matthewwrobb at gmail.com
Mon Aug 27 06:34:46 PDT 2012


So I have been trying to figure out from the wiki precisely how Private
Name Objects work. When assigned/defined does it expose that property to
all sibling properties/methods or just those present at the time of
assign/define? If you add on to the object later to the new properties get
access?

var Person = {
  [hunger]: 100,
  eat: function(){ --this[hunger]; }
}

? Person.getHunger = function() { return this[hunger] }

class Person {
  constructor(){ this[hunger] = 100; }
}

Person.prototype.getHunger = function(){ return this[hunger]; }

Does it make a difference wether it is a 'method' vs a property with a
function value?

var Person = {
  [hunger]: 100,
  eat: function(){ --this[hunger]; }
  isHungry: function() { return this[hunger] > 0; }
  getHunger() { return this[hunger]; }
}

I'm trying to determine whether when compiling into ES3/5 you could get
away with not attaching some .__privates__ property to the object and
instead just put a closure around the definitions.

Thanks ahead of time!

Matthew Robb
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20120827/dea03054/attachment.html>


More information about the es-discuss mailing list