Skip to main content
Known Participant
September 9, 2005
Question

When to use import and export directives?

  • September 9, 2005
  • 2 replies
  • 379 views
I'm very confused about what the import and export language extensions do and when one should use them.

I have a Bridge application with multiple source files. As long as I don't call code in another file from the startup execution path (before all source files are loaded) and only call across modules after Bridge is running (e.g. from events in Bridge), I don't seem to need import and export. All source files seem to be in the same namespace and all can see each other's global objects/functions.

So, when would someone use import or export? And, what is the #engine that the manual discusses in relation to import and export? If some of my source files are library files that I intend to be used by multiple different files/applications, should I be using import/export for that use? Or is this only applicable when there are somehow multiple JavaScript engines involved? And when would that situation arise?

--John
This topic has been closed for replies.

2 replies

Known Participant
September 9, 2005
OK, thanks. I'll ignore import/export for now.

--John
Known Participant
September 9, 2005
John,

The import and export directives don't really matter in Bridge. All scripts execute in the same namespace. That's why namespacing your scripts is crucial in Bridge.

The #engine directive creates another JavaScript engine instance containing the script with the directive. If you then wanted to use stuff from that engine, the import and export directives would be needed. But even with that, in Bridge, the main engine will contain the script. There will just be a second engine (you can see this in the ESTK) containing the same stuff. Since it's in the main engine, there's no point in using the import and export.

Some of the other apps, GoLive, for instance, each script executes in its own engine and namespace. And import and export are needed.

This could change in future versions, and if it does, we'll be certain to make sure everyone knows about it.

Bob