Proposal: Tagged Constructor & Taggable Function/Map/Set constructor

Sm In sbshw1 at gmail.com
Sun Mar 10 06:39:35 UTC 2019


Template literal(includes tagged template) is so strong feature.
It makes it possible to add elegant DSL for Library(or maybe framework)
which also can interact with js.([styled-component proofed this with their
api](https://www.styled-components.com/))
Why don't we use them to enhance ECMAScript's API?

If we allow using tagged template to constructors just like this:

```js
new Constructor`
  blahlah
`; // what about to call this syntax as tagged constructor?
```

we can do something like this:

#### If `Function` construcor is taggable

```js
const sum = new Function`
  (a, b) {
    return a + b;
  }
`;
```

#### If `Map` constructor is taggable

```js
new Map`
   a: 1234,
   one: ${() => 1},
   str: 'Hello!',
   bool: true
`;
```

#### If `Set` constructor is taggable. and It supports list comprehension

```js
new Set`
  ${range}
    -> ${x => x * 2}
    -> ${x => x < 10}
`; // Set [2, 4, 6, 8]
```

Feedback is welcome!
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20190310/56089a15/attachment.html>


More information about the es-discuss mailing list