[Proposal] New syntax for lazy getters
Andrea Giammarchi
andrea.giammarchi at gmail.com
Tue Jun 12 14:27:08 UTC 2018
To me decorators are the answer to pretty much everything but for the last
year I've seen zero progress on what seems to be a forever Stage 2
proposal: https://github.com/tc39/proposals#stage-2
Is there anything anyone can do to speed up adoption/implementation of that
proposal?
On Tue, Jun 12, 2018 at 4:24 PM, Augusto Moura <augusto.borgesm at gmail.com>
wrote:
> I don't think a new keyword is the right path here. For classes lazy
> fields can easily be implemented via decorators in the last proposal[1]
> (also, Groovy has previous work implementing a `@Lazy` annotation[2] with
> AST transformations for the same use case). In code something like:
> ``` js
> const lazy = (fieldMetadata) => {
> // change the field value in descriptor to a lazy factory
> };
>
> class Foo {
>
> @lazy bar = slowCalculation();
>
> @lazy statements = (() => {
> if (this.bar > 0) {
> return fooify();
> } else {
> return barify();
> }
> }());
>
> }
> ```
>
> What it's doesn't cover (and in my opinion should be the focus of a new
> proposal) is Decorators for literal objects. Something like the code below
> is yet not proposed:
>
> ``` js
> const foo = {
> @lazy bar: 3,
> };
> ```
>
> I didn't made a deep search in ESDiscuss history but I remember this
> feature being mentioned sometime ago.
>
> [1]: https://github.com/tc39/proposal-decorators
> [2]: http://groovy-lang.org/metaprogramming.html#xform-Lazy
> --
> Augusto Moura
>
> _______________________________________________
> es-discuss mailing list
> es-discuss at mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20180612/2fe9add7/attachment.html>
More information about the es-discuss
mailing list