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@mozilla.org https://mail.mozilla.org/listinfo/es-discuss