Definition mixins

Raul-Sebastian Mihăilă raul.mihaila at gmail.com
Mon Nov 13 08:45:46 UTC 2017


I wrote a first draft of the spec for the proposal (
https://github.com/raulsebastianmihaila/ecma262-definition-mixins-proposal).
In some cases I'm not certain about the accuracy of the spec and I also cut
the corners in a few places. There are 2 versions. The second version only
contains the differences from the first version. Version 1 is simpler.
Version 2 uses indirect bindings in a mixin function provider call and
these semantics don't exist in the language. I didn't try to spec them as I
thought it would be challenging (probably involving creating a new kind of
function). If this is not pragmatic it's fine, version 1 doesn't have
indirect bindings. I like version 2 a bit more, but version 1 would work as
well.

Any feedback from people from TC39 or people interested in mixins is
appreciated.

Compare the following two fragments, one with current ES syntax/semantics,
and the other one with the mixin syntax/semantics (from the first simpler
version of the spec).

```js
const mix = {
  kings: {},
  currentMove
};
let promotingPawn = null;
const board = boardMixin.create();

board.currentSide = null;
board.isPromoting = false;
board.isCheckmate = false;
board.isStalemate = false;
board.isDraw = false;

const isSafeMove = mix.isSafeMove = boardMixin.isSafeMove(mix);
const setBoardResolution = mix.setBoardResolution =
boardMixin.setBoardResolution(board, mix);

board.isSquareAttacked = boardMixin.isSquareAttacked(board);
board.getPiece = boardMixin.getPiece(board);
```

```js
const mixState = {
  kings: {},
  currentMove
};
let promotingPawn = null;
const board = boardMixin.create();

board.currentSide = null;
board.isPromoting = false;
board.isCheckmate = false;
board.isStalemate = false;
board.isDraw = false;

mixin board:
  boardMixin.isSafeMove,
  boardMixin.setBoardResolution:
    mixState;

mixin on board:
  boardMixin.isSquareAttacked,
  boardMixin.getPiece;
```
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20171113/8a0e9a24/attachment.html>


More information about the es-discuss mailing list