Hoisting between different files

前端 未结 3 1312
被撕碎了的回忆
被撕碎了的回忆 2021-01-21 22:13

Is there a way to do functions and variable hoisting between source code present in different files? That is, something like

//Inside firstfile.js
foo === \"bar\         


        
3条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-01-21 22:54

    All script tags that browser encounters are parsed and executed immediately. This is because of document.write API, that might require to browser to output something to the DOM. This means that in this situation #script1's has to finish before #script2.

    
    
    

    You might want to check what the behaviour when using ASYNC and DEFER attributes. They are supported in Webkit.

提交回复
热议问题