Module scope

33 views
Skip to first unread message

Thiago Temple

unread,
Jan 14, 2016, 8:47:57 PM1/14/16
to SystemJS
Hi, I'm playing a little with SystemJS and I have a question about the scope:

Aren't modules suppose to be isolated? I mean, functions and variables that aren't exported shouldn't be in the global scope, right?

I wrote a small script just to test it:

var message = 'Hello World';

function sayHello() {
    console.log(message);
}

console.log('app loaded');

And in my page I'm loading the module using:

System.import('js/app.js');

When I open, the console I can access window.message and window.sayHello. Is that right? I thought that because I haven't exported them they wouldn't be available.

Thanks

Guy Bedford

unread,
Jan 15, 2016, 9:43:28 AM1/15/16
to Thiago Temple, SystemJS
Modules without any import or export syntax are treated as global modules for compatibility.

You can tell SystemJS the module format through metadata and if you set the format to ES module, then these variables won't leak to the global.

--
You received this message because you are subscribed to the Google Groups "SystemJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email to systemjs+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Thiago Temple

unread,
Jan 15, 2016, 11:15:07 AM1/15/16
to SystemJS, vin...@gmail.com
Thanks, just to be clear, this is a feature of SystemJS? Not something that is drafted in es6 module loader spec?

Guy Bedford

unread,
Jan 15, 2016, 11:16:44 AM1/15/16
to Thiago Temple, SystemJS
Yes exactly.
Reply all
Reply to author
Forward
0 new messages