Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to feature-detect es6 modules

Tags:

I'd like to export a module using the ES6 syntax only if it is supported in the current runtime. The goal is to develop a library that support different module management systems.

As export is a keyword, something like will throw a syntax error :

typeof export 
like image 648
krampstudio Avatar asked Jan 13 '15 12:01

krampstudio


People also ask

Is ES6 synchronous or asynchronous?

ES6 module loaders will be asynchronous while node. js module loaders are not. Here are some key aspects of module loaders: Module code automatically runs in strict mode and there's no way to opt-out of strict mode.

Can ES6 modules have side effects?

Examples of side effects:A polyfill that enables ES6 features in the browsers that don't support them, like babel polyfill is a side effect. Many jQuery plugins attach themselves to the global jQuery object. Analytics modules that run in the background, monitor user interaction, and send the data to a server.

Do you know about anything in ES6 modules?

ES6 comes to your rescue with the concept of Modules. A module organizes a related set of JavaScript code. A module can contain variables and functions. A module is nothing more than a chunk of JavaScript code written in a file.


1 Answers

Use

 'noModule' in HTMLScriptElement.prototype  

ref

like image 68
darkziul Avatar answered Sep 30 '22 18:09

darkziul