Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.


  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • DownloadDownload
  • PrintPrint

8.5. Summary

JavaScript presents some unique performance challenges related to the way you organize your code. As web applications have become more advanced, containing more and more lines of JavaScript to function, some patterns and antipatterns have emerged. Some programming practices to keep in mind:

  • Avoid the double evaluation penalty by avoiding the use of eval() and the Function() constructor. Also, pass functions into setTimeout() and setInterval() instead of strings.

  • Use object and array literals when creating new objects and arrays. They are created and initialized faster than nonliteral forms.

  • Avoid doing the same work repeatedly. Use lazy loading or conditional advance loading when browser-detection logic is necessary.

  • When performing mathematical operations, consider using bitwise operators that work directly on the underlying representation of the number.

  • Native methods are always faster than anything you can write in JavaScript. Use native methods whenever available.


  

You are currently reading a PREVIEW of this book.

                                                                                        

Get instant access to over
$1 million worth of books and videos.

  

Start a Free Trial