Class data member declarations proposal idea

Aaron Gray aaronngray.lists at
Tue Aug 7 19:17:24 UTC 2018


I am looking for help working on a TC39 proposal for declaring class data
members, their default values, and possibly annotated typing. The fact that
this is missing means there is little continuity between classes and
existing prototypical object declarations. I have been moving Backbone.js
and Underscore.js to modern class'ized JavaScript and have found that this
will be needed for moving existing JavaScript libraries forward.

abstracted syntax example :-

    class X extends Y {
        constructor() { ... }
        defaults = {
            a: 1,
            b: 2
        x : Integer = 3
        aMethod() { ... }

syntax modifications :-

    ClassElement [Yield, Await]:
        MethodDefinition [?Yield, ?Await]
        "static" MethodDefinition [?Yield, ?Await]
        "static" FieldDefinition

        Identifier "=" PrimaryExpression

This is probably slightly oversimplified at this stage with the syntactic
rules, but this gives a preliminary idea of what is being proposed. This is
similar to the following proposal but I have shown the idea of
declaring subobject default value declarations.

Type annotations would also be a good idea and allow at the least initial
type checking for the default values, but this would not fit with subobject
declarations and is a very complex area to take forward for any more level
of type checking, although Facebook's Flow and MicroSoft's TypeScript, and
a Babel plugin flow-runtime demonstrate that this is possible.

Aaron Gray

Independent Open Source Software Engineer, Computer Language Researcher,
Information Theorist, and amateur computer scientist.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the es-discuss mailing list