将ES6重新导出的值包装到Getter中 [英] ES6 re-exported values are wrapped into Getter
本文介绍了将ES6重新导出的值包装到Getter中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有人可以向我解释吗?假设我有以下两个模块:
Can somebody explain this to me? Let's say I have these two modules:
// moduleTwo.js
export const module2Func = () => {
return 2
}
还有
// moduleOne.js
export * from './moduleTwo'
export const module1Func = () => {
return 1
}
然后我将 moduleOne 导入到某个地方:
And then I import moduleOne somewhere:
import * as final from './moduleOne'
console.log(final)
然后将最终结果转换为如下内容:
Then final results into something likes this:
{ module2Func: [Getter], module1Func: [Function: module1Func] }
为什么将module2Func
包装到Getter
中?语法是export from
吗?所有功能均按预期工作.我正在使用Babel 6来转译代码.
Why is module2Func
wrapped into a Getter
? It is the export from
that syntax does that? All functions work as expected. I'm using Babel 6 to transpiler code.
谢谢您的解释!
推荐答案
Babel正在正确实施查看编译后的输出.
That's Babel's doing to correctly implement reference binding of module imports. You can look at the compiled output.
输入:
export * from 'foo';
输出:
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
var _foo = require('foo');
Object.keys(_foo).forEach(function (key) {
if (key === "default") return;
Object.defineProperty(exports, key, {
enumerable: true,
get: function get() {
return _foo[key];
}
});
});
这篇关于将ES6重新导出的值包装到Getter中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文