【问题标题】:es6 export of a function doesn't workes6导出函数不起作用
【发布时间】:2016-06-09 09:03:31
【问题描述】:

我希望我的模块能够导出多个函数和数值常量。 当我导入模块的所有导出属性时,我发现函数实际上并未导入。

//module1.js
const func1 = (a) => {console.log(1)}; 
const func2 = (b) => {console.log(2)}; 
const variable1 = 1;
const variable2 = 2;

export const exp1 = func1;
export const exp2 = func2;
export const exp3 = variable1; 
export const exp4 = variable2; 

.

//anotherFile.js
import * as module1 from './module1';
console.log(JSON.stringify(module1, null, 2));                   // {"module1": {"exp3":1, "exp4":2}}

导入函数的正确方法是什么?

【问题讨论】:

    标签: ecmascript-6


    【解决方案1】:

    一切正常!

    我的问题出在console.log(JSON.stringify(module1, null, 2)); JSON.stringify 正在切断我的功能

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-06-11
      • 1970-01-01
      • 2016-12-11
      • 2017-02-23
      • 2018-07-04
      • 2016-06-03
      • 2021-03-09
      • 1970-01-01
      相关资源
      最近更新 更多