小编Gre*_*dev的帖子

揭示模块模式结合 ES6 模块

我不知道 ES6 模块和揭示模块模式哪种方法更好。ES6 模块的数据/功能是否与 IIFE 一样私密?

我应该只使用 *only ES6 模块,像这样:

// Export file

export const test = () => {
 console.log('Hello from test');
}

// Import file

import { test } from "./test.js";

test();
Run Code Online (Sandbox Code Playgroud)

或者我应该同时使用两者

// Export file

export const revealingPattern = (function() {
    function test() {
        console.log('Hello from test');
    }

    return {
        test
    }
})();

// Import file

import { revealingPattern } from "./test.js";
revealingPattern.test();
Run Code Online (Sandbox Code Playgroud)

javascript module revealing-module-pattern ecmascript-6 es6-modules

2
推荐指数
1
解决办法
493
查看次数

ES6 模块 - 3 种导入文件的方式

大家好,我有一个关于将文件导入单个 .js 文件的小问题。

哪种方式更好(最佳实践),用于的场景是什么:

  1. import './file;'

  2. import { something } from './file'

  3. import * as evertything from './file'

因为我看到了,2并且3是相同的东西,但语法不同(也许Syntactic Sugar)。

javascript import module export es6-modules

0
推荐指数
2
解决办法
1428
查看次数