我正在研究 Kyle Simpson 的“你不懂 JavaScript”系列。在(2014 年发布)“Scope & Closures”(第 62 页)的末尾,ES6 中有一个使用关键字“module”导入整个模块的示例,如下所示:
// import the entire "foo" and "bar" modules
module foo from "foo";
module bar from "bar";
console.log(
bar.hello( "rhino" )
);
foo.awesome();
但是,此代码不起作用。我的问题是:module
关键字是经过试验后删除的吗?我应该忘记这个关键字吗?
最佳答案
错别字
// import the entire "foo" and "bar" modules
import foo from "foo"; //fixed
import bar from "bar"; //fixed
console.log(
bar.hello( "rhino" )
);
foo.awesome();
有时候,书中的例子并不是 100% 准确的打字错误,它们确实会让初学者感到困惑。
关于JavaScript 模块关键字,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52637980/