The properties and methods added internally to the window object cannot be obtained outside the jquery ready function.

Code:

$(function(){

window.a=function(){}
window.a//Function

})

window.a//undefined

Why can"t properties be added internally to the window object? What should I do if I want to expose some methods to external calls?

Mar.13,2021

DMO loading process:

Web page document loading is performed sequentially. The general order of browser rendering operation is roughly the following steps:

1. Parsing HTML structure

2. Load external scripts and stylesheet files

3. Parse and execute the script code-this is where window.xxx is called externally

4. Construct the HTML DOM model-this is where the ready function is executed, that is, window.xxx has been called before the ready function is executed, so an error will be reported

5. Load external files such as pictures

6. Page loaded

Menu