The time function of JavaScript

Source: Internet
Author: User

In
Some development scenarios, we may inject thousands of nodes into the document at once, and in a short time the large number of DOM nodes in the browser may be too much for the browser, the result will often make the browser lag or unbearable, one of the solutions is to use the Tick function (timechunk).

The Timechunk function makes the creation of nodes work in batches, such as creating 1000 nodes in a second and creating 10 nodes per 200ms instead. The specific Timechunk function is encapsulated as follows

functionTimechunk (arr, FN, count) {//arr array fn action function count per operation quantity    varobj, t; varStart =function(){        varLen = math.min (count| | 1, arr.length);  for(vari=0; i < Len; i++) {obj=Arr.shift ();    fn (obj)}}; return function(interval) {t= SetInterval (function(){            if(arr.length==0){               returnclearinterval (t)};        Start (); },interval|| 200)    }}

Application examples See https://92node.com/article/js-fen-shi.html

The time function of JavaScript

Related Article

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.