开发者

Javascript - I.E., Chrome, Firefox - How inclusion of external .js files works?

Let's say I have 3 files.

  1. index.html (HTML + javascript)
  2. somescript1.js (Javascript File)
  3. so开发者_运维问答mescript2.js (Javascript file)

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?

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. I know that the above to questions can be answered yes for atleast one of the browsers, but I really want to be assured that I can take this perspective for any major browser.


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?

Not entirely. Code in the first script that is executed immediately won't have access to anything that would be hoisted from the second script. If execution is delayed until after the second script loads (e.g. by assigning a function to the onload event) then it would have access.

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?)

Yes (subject to the aforementioned timing issue)

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

It is the same between the five major browsers (and all the minor ones).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜