On Jan 27, 2011, at 8:38 AM, Wes Garland wrote: > Kris Kowal's query is interesting: is lazy evaluation worth considering for > Simple Modules? > > module M { > export var foo = 42; > export function bar() { return foo; } > alert("hello, world"); > } > > In the example above, the alert statement would occur when the first import > from M statement were executed, rather than when the page containing the > <SCRIPT type="es-next"> were loaded.
Believe me, I have considered it. :) We thought for a while about demand-driven evaluation of modules. There are a couple reasons why I believe it would be too problematic. First, we'd really like to make the act of throwing your code into a module as transparent as possible; changing the control flow would make modules more heavyweight. But more importantly, since as you mentioned, module evaluation can contain arbitrary side effects, evaluating them lazily means laziness with side effects. This makes for really hard-to-understand and hard-to-debug initialization errors, where you end up having to write mysterious top-level imports to force evaluation of modules in particular orders. Laziness + side-effects: bad scene, man. Dave
_______________________________________________ es-discuss mailing list es-discuss@mozilla.org https://mail.mozilla.org/listinfo/es-discuss