July 25, 2012 - TC39 Meeting Notes

Allen Wirfs-Brock allen at wirfs-brock.com
Mon Jul 30 12:49:20 PDT 2012

On Jul 29, 2012, at 6:05 AM, Herby Vojčík wrote:
> Brendan Eich wrote:
>> ...
>> However TC39 favored configurable: true as well as writable: true, to
>> match JS expectations, in particular that one could reconfigure a data
>> property (which is what method definition syntax in a class body
>> creates) with a workalike accessor.
> I don't understand here.
> 1. Method syntax does not create data property (well, technically, yes, but I already think in terms of configurable: true, writable: false which was present some time already in wiki / es-discuss).
> 2. To replace data property with workalike accessor, you use Object.defineProperty, so why would you need writable: true? It is not needed there at all.

Yes, this is close to what I was thinking.  While "concise methods" are implemented as  "data properties"  they should not be thought of as part of the mutable state contract of an object. Conceptually, they are not the same thing as a closure-valued "instance variable".  I expect that future ES6 style guides with say something like:

Use concise method notation to define behavior properties of object whose modification is not part of the objet's contract. Use : data property notation to define state properties that are expected to be modified.  Always use : data properties in cases where the dynamic modification of a function-valued property is expected and part of the object's contract. For example:

class Foo {
    report () {this.callback()}  //a prototype method that is a fixed part of the Foo interface. 
    constructor (arg) {
       this := {
             callback : () => undefined,   //default per-instance callback.  clients are expected to modify
             doIt () {doSomethingWith(this, arg)} // a per-instance method that captures some constructor state, clients are not expected to modify

let f = new Foo(thing);
f.callback = () => console.log('called back');   //this sort of assignment is expected.              
f.doIt = function () {...};  //this isn't expected.  It is patching the class definition. Avoid this. 
f := {doIt () {...} };            //instead this is how you should patch class definitions.

The concise method attribute values I suggested were intended as a means of making this guideline a bit more than just a convention.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20120730/1b43ec98/attachment.html>

More information about the es-discuss mailing list