ES6 export all values from object

前端 未结 9 1800
梦谈多话
梦谈多话 2020-11-28 07:32

Say I have a module (./my-module.js) that has an object which should be its return value:

let values = { a: 1, b: 2, c: 3 }

// \"export values\         


        
9条回答
  •  星月不相逢
    2020-11-28 08:35

    export const a = 1;
    export const b = 2;
    export const c = 3;
    

    This will work w/ Babel transforms today and should take advantage of all the benefits of ES2016 modules whenever that feature actually lands in a browser.

    You can also add export default {a, b, c}; which will allow you to import all the values as an object w/o the * as, i.e. import myModule from 'my-module';

    Sources:

    • https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/export

    • http://www.2ality.com/2014/09/es6-modules-final.html

提交回复
热议问题