How can I load and run an existing library using JavaScript ES6 modules?
For example, suppose I need to load an existing polyfill:
import {poly} from "thirdParty/poly";
How to run an imported poly script and load its properties into the current namespace without changing the source?
Here are two practical problems that will help clarify the problem I'm trying to solve:
It starts and loads into the global area. How can this be done with ES6 modules?
I have another script called Font.js which is a preloader for fonts. It allows you to create a new font object as follows:
var font = new Font ();
I used Font.js, loading it with a script tag, for example:
<script src="Font.js"><script>
Without accessing, modifying, or understanding the source code of this script, how can I use ES6 modules to load and use the same as with the <script> ? I just need these scripts to run when they load and take care of themselves.
A possible solution would be to use the API Loader API:
http://wiki.ecmascript.org/doku.php?id=harmony:module_loaders
This document describes the global binding of the System loader, but I'm afraid I don't have the vocabulary to fully understand what it is trying to explain. Any help in decrypting this document would be greatly appreciated!
javascript import ecmascript-6 module ecmascript-harmony
d13
source share