This is a “thread” according to javascript, but the code doesn’t seem to fit the conventional threaded model.
Is it possible to make this code clearer, with regards to the concept of a thread?
function test() {
alert("Test");
}
// this creates a new "thread," but doesn't make much sense to the untrained eye
setTimeout(test, 0);
Is there some other way to branch off?
You are basically just taking the call to
testout of the normal flow and the engine will execute the function whenever it fits, as soon as possible. That means, you are executingtestasynchronously.To make the code clearer, you could create a function with a meaningful name which does the same:
If you want to have real threads, have a look at web workers.