<div class="blog_content">这篇是nicholas讨论如果防止脚本失控的第二篇,主要讨论了如何重构嵌套循环、递归,以及那些在函数内部同时执行很多子操作的函数。基本的思想和上一节chunk()那个例子一致,如果几个操作没有特定的执行顺序,而且互相不是依赖关系,我们就可以通过异步调用的方式加以执行,不止可以减少执行的次数,还可以防止脚本失控。本文还介绍了通过memoization技术取代递归的方法。
<div>【原文标题】
speed up your javascript, part 2<br>【原文作者】
nicholas c. zakas<br><br>
以下是对原文的翻译:<br><br>上周我在《
too much happening in a loop》(译文:
如何提升javascript的运行速度之循环篇(一))这篇文章中介绍了javascript运行时间过长的第一个原因。相似的情况有时也出现在函数的定义上,函数也可能因为使用不当而过载使用。通常情况是函数内包含了过多的循环(不是在循环中执行了过多的内容),太多的递归,或者只不过是太多不相干但又要一起执行的操作。<br><br>太多的循环经常是以嵌套的形式出现,这种代码会一直占用javascript引擎直至循环结束。这方面有一个非常著名的例子,就是使用冒泡算法排序。由于 javascript有内置的sort()方法,我们没有必要使用这种方式进行排序,但我们可以借助这个算法理解嵌套循环占用资源的症结所在,从而避免类似情况的发生。下面是一个在javascript使用冒泡排序法的典型例子:<br>
分享到:
相关推荐
to-date JavaScript programming techniquesContinuing in the superlative tradition of the first three editions, Beginning JavaScript, Fourth Edition, gets you up to speed on all the new advances in ...
Next, you will move on to learn about DOM optimization, JavaScript promises, and web workers to better break up your large codebase. You will also learn about JavaScript performance on mobile ...
Zakas 于 2009 年 1 月 20 日在个人网站上发表的《Speed up your JavaScript, Part 2》。本文主要讨论了如何重构嵌套循环、递归,以及那些在函数内部同时执行很多子操作的函数,以提高 JavaScript 的运行速度。 ...
Speed up and simplify app development with jQuery Quickly retrieve data from a server using AJAX requests Adapt your app for mobile devices with jQuery Mobile Build Windows 8 apps using HTML, CSS, and...
This completely updated second edition covers everything you need to know to get up-to-speed with JavaScript development and add dynamic enhancements to web pages, right from the basics. As well as ...
This completely updated second edition covers everything you need to know to get up-to-speed with JavaScript development and add dynamic enhancements to web pages, right from the basics. As well as ...
当谈到 JS 性能的时候,Zakas差不多就是你要找的,2010年六月他在Google Tech Talk发表了名为《Speed Up Your Javascript》的演讲。 但 Javascript 性能优化绝不是一种书面的技术,Nicholas 的技术演进列出了10条...
This book will bring programmers and non-technical professionals, including casual programmers and scripters, painlessly up to speed on all aspects of mastering JavaScript. Key topics include ...
who are just learning the language and want to come up to speed quickly. In either case we assume you have at least a basic background in programming. Chapter 1, in particular, assumes you are coming...
原文标题:Speed up your JavaScript, Part 1 原文作者:Nicholas C. Zakas 在我 上一篇帖子 (译文 ) 中,谈到了各个浏览器究竟会在什么情况下弹出脚本失控提示,对于Internet Explorer 来说,当浏览器执行了数量...
You will find plenty of fully explained code and ample screenshots in the book to ease and speed up your understanding. This book is for developers, ideally with web development experience, who are ...
You will find plenty of fully explained code and ample screenshots in the book to ease and speed up your understanding. This book is for developers, ideally with web development experience, who are ...
Learn how to speed up your development process and save valuable time Work though step-by-step tutorials that provide easy-to-understand solutions to real-world problems Book Description The ...
Use external modules to speed up the development and maintenance of your projects Explore the different UI and code patterns to be used for iOS and Android Understand the best practices which can be ...