What are extra advantage of using ES6 module instead of revealing module pattern?

Viewed 3430

I am exploring ES6 module and trying to figure out what extra advantage we get using ES6 module instead of closure along with module pattern(MP).

For example util.js in ES6.

   var util ={
         abc:function(){
        //function body
    },
    def:function(){
         // function body
    }
    export default utils;   // here export is exposing the entire object
}

util.js using closure & module pattern

var util = (function(){
       function _abc(){
         console.log("abc")
           // function body
       };
    function _def(){
         // function body
      }

  return{          // each of the function will be exposed
      abc:_abc,
      def:_def

}
}(util ||{}))

someFile.js in ES6

import {utils} from "path/to/file"

In someFile.js with closure & module pattern

util.abc() // Will log "abc"

Also I know es6 module allow us to rename imports & exports Like export { a as abc} .

With closure & module pattern we can give a name whatever we like inside return statement like return { a:_abc}

My question:What extra benefit we can get by using es6 module instead of closure& MP.One i guess is reduction in lines of code.

Please excuse me if I have missed any basic difference

1 Answers
Related