I am referring to this. Everything is still not clear.
- I have a JS function
fillTree()which updates a tree, it has checkboxes. - I have another function
checkSelectedBoxes()which is executed onwindow.onloadwhich checks for selected checkboxes. - Now there are lots of other functions connected.
My question:
- If I am using
setTimeout()will the other script function also stop and wait for my function to finish loading?
What might be the case in this:
function fillTree(){...}
function checkSelectedBoxes(){...}
fillTree(); // This take time to get data. onLoad() doesnt work.
setTimeout(function(){ checkSelectedBoxes() },5000);
This returns me null values even after increasing the time interval. Does fillTree() pause execution?
No,
setTimeoutdoes not wait for you (hence, JS has no pause function). WhatsetTimeoutdoes is set aside that task at a later time, and allow the next line to be executed. when that timeout is reached, it inserts that task into the execution line.and when no other code is running, it executes the function that was indicated.what you want to do is give a callback to your
fillTree()and execute when it’s done.