Lucan Lucan - 1 month ago 21
Node.js Question

import and export in Javascript

According to this question Include a JavaScript file in another JavaScript file?. It seems a lots of people are interested in breaking big Javascript projects into small modules and export/import modules for code reuse.

After some research, import/export are designed for this feature. According to the references, they're initially defined in ES6. However "This feature is not implemented in any browsers natively at this time." What's the status of this feature? Are they going to be implemented in future, or still in the state of draft?

(If you're using nodejs, Modules (https://nodejs.org/dist/latest-v5.x/docs/api/modules.html) is the best aproach)

Refrerences:

https://developer.mozilla.org/en/docs/web/javascript/reference/statements/import
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/export

Answer

In the current versions of JS there are a few methods of doing this. Require uses the AMD design pattern, and is the standard for frontend dependency injection / module loading. Frameworks such as Angular use this method.

Here is a link to the require docs. http://requirejs.org/