Skip to content
This repository was archived by the owner on Nov 7, 2018. It is now read-only.

Latest commit

 

History

History
54 lines (40 loc) · 1.18 KB

classsyntax.md

File metadata and controls

54 lines (40 loc) · 1.18 KB

Class syntax

This is just a sketch, but the idea is to extend class type syntax to integrate with typed objects.

WARNING: This is very preliminary and not fully thought through.

Field types

Allow users to declare field types. If any field types exist, this class syntax will be desugared into a typed object definition.

class PointType {
    r: uint8;
    g: uint8;
    b: uint8;
    a: uint8;
    
    constructor(r, g, b, a) {
        this.r = r; ...
    }
}

desugars into something like:

var _PointType = new StructType({r: uint8, g: uint8, b: uint8, a: uint8});
class PointType(_PointType) {
    constructor(r, g, b, a) {
        this.r = r; ...
    }
}

Sealed classes

It'd also be nice to be able to have classes whose prototypes are sealed after they are constructed. This gives better optimization opportunities. It is orthogonal to the syntax above.

sealed class Foo { ... }`

desugars into something which freezes Foo.prototype after construction.

Open questions

  • How to integrate class syntax with forward references.
  • Can we integrate with module loading somehow to avoid the need for forward references when using declarative syntax?