Asynchronous from setTimeout and setInterval to AJAX in JavaScript, setintervalajax
SetTimeout and setInterval
First, let's take a look at the following code to print the result.
console.log(1);setTimeout(function() { console.log(2); },100)setTimeout(function() { console.log
SetTimeout in JavaScript: settimeout in js
1. setTimeout: single thread
For a long time, we have been saying that Javascript is a single thread. No matter when the browser is running, there is only one thread running JavaScript programs.
However, I don't know if you have any questions. It's our setTimeout (like setInte
and GUI rendering threads, browser event trigger thread.
The javascript engine is based on the event-driven single-thread execution. The JS engine keeps waiting for the arrival of tasks in the task queue and then processes them, the browser has only one JS thread running the JS program at any time.
The GUI rendering thread is responsible for rendering the browser interface. When the interface needs to be repainted or reflow is triggered due to some operation, this thread will execute. How
SetTimeout () recursive call without quotation marks error solution, settimeout Recursion
SetTimeout () is used to implement recursive calling. If the first parameter is not enclosed in quotation marks, Firefox prompts setTimeout (): uselesssetTimeout call (missing quotes around argument ?) If the quotation marks are a
following explanation comes from this blog:JavaScript is a single-threaded execution and cannot execute multiple pieces of code at the same time. When a piece of code is executing, all subsequent tasks must wait to form a queue. Once the current task is completed and the next task is removed from the queue, this is often referred to as "blocking execution." So a mouse click, or a timer arrives at a point in time, or an AJAX request is completed trigg
the interval between two triggers is greater than the preset value. Assuming that the interval between two Ajax communications is no less than 2500 milliseconds, the above code can be rewritten as follows.$ ('Textarea '). on ('keylow', debounce (ajaxAction, 2500 ))You can use setTimeout and clearTimeout to implement the debounce method. This method is used to prevent a function from being i
JavaScript timer SetTimeout: regularly refresh and close windows (code is super simple), js timer settimeout
If you don't talk much about it, You can directly post code to everyone.
// Refresh the current window setTimeout ("self. location. reload (); ", 5000); // js closes the window at regular intervals (tested in ie and FF) // closes the current window
The settimeout in the textbook
The definition is simple.
The settimeout () method is used to call a function or evaluate an expression after a specified number of milliseconds.
Wide Application Scenarios
Timer, Carousel graph, animation effect, automatic scrolling, etc.
Some of the above should be settimeout in the hearts of everyone, because we usually use is no
The example explains the usage of setTimeout () in JS, and the example explains settimeout.
This article explains the usage of setTimeout () in JS and shares it with you for your reference. The specific content is as follows:
:
Code:
The following describes the specific usage:
1. ParametersCode (required): (the original meaning of the code) the JavaScript code
For Loop + setTimeout combined with some examples (front-end interview questions), settimeout front-end
I. background
I recently reviewed the old book "node. js Development Guide" and encountered a typical example of for loop + setTimeout. So I reorganized my ideas and recorded them.
2. execution mechanism of setTimeout
SetTimeout (), setInterval (), settimeout
The setTimeout () and setInterval () methods are both JavaScript timing events.
Same
1. Both are two methods of html dom Window object
Can be written
Window. setTimeout ();
Window. setInterval ();
Of course, you can do this without adding a window.
2. Both have two parameters.
One interview experience on setTimeout front-end and one experience on settimeout
Preface
The frontend is a hot field in recent years, and the atmosphere is very strong. My friend Xiaowei has recently been in a crazy interview and has met many interesting interviewers and interesting interview questions, let me tell you something about it.
The details are as follows:
The following is a story from a friend o
process of the following code can be thoroughly understood here. The execution engine first writes the setTimeout () method into the stack and submits the delay method to the corresponding kernel module for processing during execution. The engine continues to process the following code. The while statement blocks the engine for 1 second. During this process, the kernel timer module adds the latency Method to the task queue at 0.5 seconds, after the e
method to the task queue at 0.5 seconds, and after the engine execution stack is emptied, the engine takes the delay method into the stack and processes it, and the final output time exceeds the expected set time.var New date;settimeout (function() {varnew date;console.log (' time Elapsed: ', End-start, ' Ms '; while (new Date-start The Webapis section mentioned in the previous event Loop Model diagram mentions DOM events,
loop is a first-in (FIFO) queue, This means that callbacks are executed in the order in which they were queued (in the same case. ), but if the delay time is not the same, then it will not, as the above-mentioned in the case of the timing of the number of milliseconds to change the output of the difference.Four: Types of asynchronous functionsThe asynchronous functions provided in the JavaScript environment are divided into 2 main categories: I/O functions and timing functions.One: asynchronous
queued (in the same case. ), but if the delay time is not the same, then it will not, as the above-mentioned in the case of the timing of the number of milliseconds to change the output of the Difference.Four: types of asynchronous functionsThe asynchronous functions provided in the JavaScript environment are divided into 2 main categories: I/O functions and timing functions.We all know that creating nodejs is not about running JavaScript on the server, but because the JavaScript language can p
order in which they were queued (in the same case. ), but if the delay time is not the same, then it will not, as the above-mentioned in the case of the timing of the number of milliseconds to change the output of the difference.Four: Types of asynchronous functionsThe asynchronous functions provided in the JavaScript environment are divided into 2 main categories: I/O functions and timing functions.We all know that creating nodejs is not about running JavaScript on the server, but because the
One, settimeout those things of the single thread
All along, everyone is saying that JavaScript is single-threaded, and that browsers are running JavaScript programs whenever and only one thread.
However, do not know that there is no question--that is, we are in the programming process of the settimeout (similar to the setinterval, Ajax), not asynchronous execu
event loop until the asynchronous function is finished, which means that JavaScript is not multi-threaded, and the event loop is a first-in, first-out (FIFO) queue, This means that callbacks are executed in the order in which they were queued (in the same case. , but if the delay time is not the same, then will not be, as the above the case of the timing of the number of milliseconds to change the size of the output is not the same.
Four: Types of asynchronous functions
The asynchronous funct
.
The GUI rendering thread is responsible for rendering the browser interface, which executes when the interface needs to be redrawn (Repaint) or when a return (reflow) is caused by an operation. However, it is important to note that the GUI rendering thread is mutually exclusive to the JS engine, and when the JS engine executes, the GUI thread is suspended, and the GUI update is saved in a queue until the JS engine is idle and executed immediately.
An event triggers a thread that, whe
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.