| [ Web Proxy ] |
| Viewing: https://developer.mozilla.org/zh-TW/docs/Web/JavaScript/Reference/Execution_model | [Back] [Original] |
Get to know MDN better
JavaScript concurrency modelevent loop C Java
JavaScript
Function frame
function foo(b) {
var a = 10;
return a + b + 11;
}
function bar(x) {
var y = 3;
return foo(x * y);
}
console.log(bar(7));
bar bar frame bar foo foo frame foo frame bar frame bar
JavaScript function function
while (queue.waitForMessage()) {
queue.processNextMessage();
}
queue.waitForMessage
C C
a script taking too long to run
setTimeout 0setTimeout
setTimeout
const s = new Date().getSeconds();
setTimeout(function () {
// prints out "2", meaning that the callback is not called immediately after 500 milliseconds.
console.log("Ran after " + (new Date().getSeconds() - s) + " seconds");
}, 500);
while (true) {
if (new Date().getSeconds() - s >= 2) {
console.log("Good, looped for 2 seconds");
break;
}
}
callback function 0 0 setTimeout
this is just a message setTimeout
(function () {
console.log("this is the start");
setTimeout(function cb() {
console.log("this is a msg from call back");
});
console.log("this is just a message");
setTimeout(function cb1() {
console.log("this is a msg from call back1");
}, 0);
console.log("this is the end");
})();
// "this is the start"
// "this is just a message"
// "this is the end"
// "this is a msg from call back"
// "this is a msg from call back1"
Web worker cross-origin iframe postMessage message
This page was last modified on 2025716 by MDN contributors.
Your blueprint for a better internet.
Portions of this content are 19982026 by individual mozilla.org contributors. Content available under a Creative Commons license.
| Web Proxy Viewer | New URL | Original Page |