Tôi có đoạn code:ES6 mô-đun phạm vi
// lib.js
var a = "a";
export var b = "b";
// main.js
console.log(a); // "a" variable is not available in a global scope
import {b} from "lib";
console.log(a); // is "a" variable available in a global scope or only in a module scope?
Tôi có thể sử dụng "a" biến trong một phạm vi toàn cầu sau khi mô-đun nhập khẩu hoặc là nó chỉ có trong một phạm vi mô-đun? ES6 module sẽ có một nguyên tắc làm việc tương tự như thủ thuật này:
// module
exports.module1 = (function(){ var a = "a"; })(); // "a" variable is not available in a global scope
Cảm ơn bạn rất nhiều. –