On Mon, Aug 18, 2008 at 1:44 PM, <[EMAIL PROTECTED]> wrote:
> Consider a module file located at the URL --
>
> http://foo.com/someModule.js
>
> containing the text --
>
> var isOn = false;
> provide
> toggle: function() {
> document.setBackgroundColor(isOn ?
> background : '#ffffff');
> isOn = !isOn;
> },
> set: function() {
> document.setBackgroundColor(background);
> isOn = true;
> };
>
> This code has two free variables, "document" and "background", and
> returns the symbols "toggle" and "set" to the importer.
I'll note that JavaScript seems strangely in between being an
expression language and a statement language. For most purposes,
statements are evaluated only for effect, not value. However, a
program evaled as a string yields a value as one would expect of an
expression language. In squarefree on FF:
eval('for(var i = 0; i < 1; i++){if (true){i+1}}')
1
It looks like the relevant part of ES3 is 15.1.2.1 step 3: "Evaluate
the program from step 2."
If we decide that a module body is to be treated as an evaled program,
then Ihab's example above can be simply:
var isOn = false;
{
toggle: function() {
document.setBackgroundColor(isOn ?
background : '#ffffff');
isOn = !isOn;
},
set: function() {
document.setBackgroundColor(background);
isOn = true;
}
}
--
Cheers,
--MarkM
_______________________________________________
Es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss