Igor Vaynberg (2017-01-06T22:11:57.000Z)
Given a simple class with an abstract method "populateItem"

class ArrayView extends Container {
    constructor(id, model) {
        super(id);
        this.model = model;
    }

    // methods referencing "populateItem" omitted for clarity
}

the current anonymous instantiation syntax looks like this:

this.add(new class extends ArrayView {
    populateItem(item) {
        item.add(new Checkbox("check", new PropertyModel(item.model, "done")));
        item.add(new Label("title", new PropertyModel(item.model, "title")));
    }
}
("items", itemsModel)
);

The problem with this syntax is that it pushes the constructor
parameters below the class body which I think causes two problems:

When scanning code constructors often contain the piece of information
that helps locate the anonymous class, which currently requires the
developer to look back. This is especially problematic for anonymous
classes with long class bodies.

When writing code I usually think about the constructor first, so it
seems it would be preferable to write it before moving onto working on
the class body. This is also the reason why constructors are usually
placed toward the top of named classes' source.

A better syntax would move the constructor parameters between the
super class name and the class body:

this.add(new class extends ArrayView("items", itemsModel) {
    populateItem(item) {
        item.add(new Checkbox("check", new PropertyModel(item.model, "done")));
        item.add(new Label("title", new PropertyModel(item.model, "title")));
    }
});

If possible it would also be great to get rid of the "class extends"
keywords for this usecase:

this.add(new ArrayView("items", itemsModel) {
    populateItem(item) {
        item.add(new Checkbox("check", new PropertyModel(item.model, "done")));
        item.add(new Label("title", new PropertyModel(item.model, "title")));
    }
});

Thoughts?


Thanks,
-igor
forbes at lindesay.co.uk (2017-01-08T05:20:18.259Z)
Given a simple class with an abstract method "populateItem"

```js
class ArrayView extends Container {
    constructor(id, model) {
        super(id);
        this.model = model;
    }

    // methods referencing "populateItem" omitted for clarity
}
```

the current anonymous instantiation syntax looks like this:

```js
this.add(new class extends ArrayView {
    populateItem(item) {
        item.add(new Checkbox("check", new PropertyModel(item.model, "done")));
        item.add(new Label("title", new PropertyModel(item.model, "title")));
    }
}
("items", itemsModel)
);
```

The problem with this syntax is that it pushes the constructor
parameters below the class body which I think causes two problems:

When scanning code constructors often contain the piece of information
that helps locate the anonymous class, which currently requires the
developer to look back. This is especially problematic for anonymous
classes with long class bodies.

When writing code I usually think about the constructor first, so it
seems it would be preferable to write it before moving onto working on
the class body. This is also the reason why constructors are usually
placed toward the top of named classes' source.

A better syntax would move the constructor parameters between the
super class name and the class body:

```js
this.add(new class extends ArrayView("items", itemsModel) {
    populateItem(item) {
        item.add(new Checkbox("check", new PropertyModel(item.model, "done")));
        item.add(new Label("title", new PropertyModel(item.model, "title")));
    }
});
```

If possible it would also be great to get rid of the "class extends"
keywords for this usecase:

```js
this.add(new ArrayView("items", itemsModel) {
    populateItem(item) {
        item.add(new Checkbox("check", new PropertyModel(item.model, "done")));
        item.add(new Label("title", new PropertyModel(item.model, "title")));
    }
});
```

Thoughts?