javascript中的变量范围是什么?它们的内部是否与函数外部相同?或者甚至重要吗?另外,如果变量是全局定义的,那么它们存储在哪里?
我正在测试ES6模块,并希望让用户使用onclick以下方法访问一些导入的函数:
的test.html:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Module Test</title>
</head>
<body>
<input type="button" value="click me" onclick="hello();"/>
<script type="module">import {hello} from "./test.js";</script>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
test.js:
export function hello() {console.log("hello");}
Run Code Online (Sandbox Code Playgroud)
当我单击按钮时,开发人员控制台会说:ReferenceError:未定义hello.如何从模块导入函数,以便它们可用作onclick函数?
我正在使用Firefox 54.0 dom.moduleScripts.enabled设置为true.