tc39 / proposal-private-methods

Private methods and getter/setters for ES6 classes
https://arai-a.github.io/ecma262-compare/?pr=1668
345 stars 37 forks source link

Editorial: Phrase private methods as brands, not fields #52

Closed littledan closed 5 years ago

littledan commented 5 years ago

Many people attempting to implement private methods, both in transpilers and native JS engines, have run into similar sources of confusion about semantics and optimizability:

To clear things up, this patch rephrases private methods and accessors' semantics as being based on a brand check, followed by a function call. Each object has a list of "private brands" it supports, which are identified by Klass.prototype, for classes Klass which have private methods or accessors. Private names are considered to have both a reference to this brand as well as the actual method linked from them. My hope is that this will be a reasonable first-pass implementation strategy; there is a note about how to optimize the brand list further.

With this change, the static class features needs some simple changes, and the decorators proposal needs some larger changes. See https://github.com/tc39/proposal-decorators/issues/180 for details.

littledan commented 5 years ago

OK, I'm going to land this patch so it's more easy to read this version. If anyone has concerns with it, please say so here, and I can roll it back.