Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the term used to describe a complete call frame cycle thing in JavaScript?

In JavaScript, there is the concept of the execution pathway beginning at a certain point (such as an event handler), with the control being relinquished back to the browser at some point.

Is there a proper name for this process?

Originally I thought you could refer to this as the "current Stack Frame", but after reading Wikipedia I see that refers to something else. It's not the call stack, that's the breadcrumb of where we've been.

(Apologies for the awkward title ... I'm open to suggestions :))

like image 236
Paul Go Avatar asked May 15 '15 18:05

Paul Go


People also ask

What is the call stack in JavaScript?

A call stack is a mechanism for an interpreter (like the JavaScript interpreter in a web browser) to keep track of its place in a script that calls multiple functions — what function is currently being run and what functions are called from within that function, etc.

What is the event loop in JavaScript?

JavaScript has a runtime model based on an event loop, which is responsible for executing the code, collecting and processing events, and executing queued sub-tasks. This model is quite different from models in other languages like C and Java.

What is callback queue in JavaScript?

A callback queue is a queue of tasks that are executed after the current task. The callback queue is handled by the JavaScript engine after it has executed all tasks in the microtask queue.

When a JavaScript function is invoked called in node where is a new frame placed?

If a function calls another function, the JavaScript engine creates a new function execution context for the function that is being called and pushes it on top of the call stack.


2 Answers

I've heard this called a "turn of the event loop" (by engineers at Mozilla and by members of TC39, the ECMAScript standard committee).


In the ECMAScript standard, a Job is defined as "an abstract operation that initiates an ECMAScript computation when no other ECMAScript computation is currently in progress". That's exactly what you're looking for, but the term isn't widely used.

The HTML standard describes event loops in bewildering detail, but the term it uses, task, isn't widely used either.

like image 105
Jason Orendorff Avatar answered Sep 29 '22 15:09

Jason Orendorff


I don't think there is a well-established, standard term for what you're asking about.

I've just heard it as "back to the event loop" or "finish the current thread of execution and return to the event loop".

And, node.js uses the term "next tick" to mean something similar.

Javascript (in both a browser and in node.js) is event driven and all asynchronous operations or user events get executed by putting an event in the event queue and that event gets processed only when the current thread of execution is done and the JS engine can then pull the next event off the event queue and start its execution. So, because the underlying mechanism is an event queue driven it is common to use the phrase "event" in whatever term you use to describe it.

This article on Understanding process.nextTick() refers to "every tick of the event loop".

You can imagine this event loop to be a queue of callbacks that are processed by Node on every tick of the event loop.

The node.js documentation for process.nextTick() uses "event loop turn runs to completion".

Once the current event loop turn runs to completion, call the callback function.

The node.js documentation for setImmediate() refers to "event loop iteration".

Callbacks for immediates are queued in the order in which they were created. The entire callback queue is processed every event loop iteration. If you queue an immediate from inside an executing callback, that immediate won't fire until the next event loop iteration.

like image 29
jfriend00 Avatar answered Sep 29 '22 15:09

jfriend00