gpt4 book ai didi

Javascript - I.E.、Chrome、Firefox - 如何包含外部 .js 文件?

转载 作者:行者123 更新时间:2023-11-29 10:23:43 24 4
gpt4 key购买 nike

假设我有 3 个文件。

  1. index.html(HTML + javascript)
  2. somescript1.js(Javascript 文件)
  3. somescript2.js(Javascript 文件)

将所有三个文件中涉及的 javascript 视为“串联”在一起,使它们成为一个长脚本,变量和函数可在所有三个文件之间访问是否​​合适?

如果定义了多个同名函数,只使用最后一个函数,对吗? (这样一来,如果我在父 index.html 的末尾 定义一个函数,它将覆盖 javascript 链接文件中定义的函数?)

根据给出的答案,我想知道这三个主要浏览器之间是否相同。我知道以上问题对于至少一种浏览器的回答是肯定的,但我真的想确保我可以对任何主流浏览器采取这种观点。

最佳答案

Is it appropriate to view the javascript involved in all three of the files as being "concatenated" together such that they are one long script with variables and functions accessible between all three?

不完全是。立即执行的第一个脚本中的代码将无法访问将从第二个脚本提升的任何内容。如果执行被延迟到第二个脚本加载之后(例如,通过将函数分配给 onload 事件),那么它将可以访问。

If multiple functions of the same name are defined only the last one is used correct? (Such that if I define a function at the end of the parent index.html it will override the ones defined in the javascript linked files?)

是(取决于上述时间问题)

With the answer given I would like to know if it is the same between all three major browsers.

五个主要浏览器(以及所有次要浏览器)之间都是一样的。

关于Javascript - I.E.、Chrome、Firefox - 如何包含外部 .js 文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6293844/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com