Jump to content

How Does Jquery Constantly Check For State?


omgRawr
 Share

Recommended Posts

You know how there are jQuery functions that "wait" for events to occur first? Like there is $(document).ready() that keeps checking until the document is completely loaded, or the effects which update themselves? I wanted to know how that works. How does jQuery constantly check for state? Say for $(document).ready(), does it repeatedly call setTimeout() on a function that checks the state of the document until the document finishes loading? Or does it use a stack or something similar? I'm really curious about this, and also how its animations work.

Link to comment
Share on other sites

You should be able to check the source of jquery to see how they do anything, but the browser will automatically fire whatever events it has built-in. Whatever was subscribed to those events will fire when the event fires. For custom events, it will probably use an event registration model where it stores a reference to each event handler for the events of whatever object you're registering an event handler with, and in the function to run that event it will check to see if there are any handlers registered and execute those if so.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...