在身体中未识别的头部定义的功能?
大家
<script type="module">
import {g1} From './scripts/main.js';
myFunction(){
do something, g1 is called
}
</script>
好
<script>
myFunction();
</script>
与头部类型属性的错误?
Hi all I'm learning javascript and have run into a problem when defining a function in head utilizing imported functions:
<script type="module">
import {g1} From './scripts/main.js';
myFunction(){
do something, g1 is called
}
</script>
when I call myFunction in body I get a myFunction() not defined error:
<script>
myFunction();
</script>
My understanding is this should work, am I making a mistake with the type attribute in head?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在JS中,给定代码的范围仅像这样执行:
(1)全局范围&gt; (2)模块范围,然后&gt; (3)功能范围
意味着您尝试访问全局范围中的模块范围变量/函数,您需要在某个地方进行编码。您的选项是:
In JS the scope of a given code is executed simply like so:
(1) Global scope > (2) Module scope and then the > (3) Function scope
Meaning that you try to access a module scope variable/function in the global scope, you need to restructure you code someway. Your options are: