[·Òë]High Performance JavaScript(015)
µÚÎåÕ Strings and Regular Expressions ×Ö·û´®ºÍÕýÔò±í´ïʽ
Practically all JavaScript programs are intimately tied to strings. For example, many applications use Ajax to fetch strings from a server, convert those strings into more easily usable JavaScript objects, and then generate strings of HTML from the data. A typical program deals with numerous tasks like these that require you to merge, split, rearrange, search, iterate over, and otherwise handle strings; and as web applications become more complex, progressively more of this processing is done in the browser.
¼¸ºõËùÓÐJavaScript³ÌÐò¶¼Óë×Ö·û´®²Ù×÷½ôÃÜÏàÁ¬¡£ÀýÈ磬Ðí¶àÓ¦ÓóÌÐòʹÓÃAjax´Ó·þÎñÆ÷»ñÈ¡×Ö·û´®£¬½«ÕâЩ×Ö·û´®×ª»»³É¸üÒ×ÓõÄJavaScript¶ÔÏó£¬È»ºó´ÓÊý¾ÝÖÐÉú³ÉHTML×Ö·û´®¡£Ò»¸öµäÐ͵ijÌÐòÐèÒª´¦ÀíÈô¸ÉÕâÑùµÄÈÎÎñ£¬ºÏ²¢£¬·Ö½â£¬ÖØÐÂÅÅÁУ¬ËÑË÷£¬±éÀú£¬ÒÔ¼°ÆäËû·½·¨´¦Àí×Ö·û´®¡£Ëæ×ÅÍøÒ³Ó¦ÓÃÔ½À´Ô½¸´ÔÓ£¬Ô½À´Ô½¶àµÄ´ËÀàÈÎÎñ½«ÔÚä¯ÀÀÆ÷ÖÐÍê³É¡£
In JavaScript, regular expressions are essential for anything more than trivial string processing. A lot of this chapter is therefore dedicated to helping you understand how regular expression engines internally process your strings and teaching you how to write regular expressions that take advantage of this knowledge.
ÔÚJavaScriptÖУ¬ÕýÔò±í´ïʽÊDZز»¿ÉÉٵĶ«Î÷£¬ËüµÄÖØÒªÐÔÔ¶³¬¹ýËöËéµÄ×Ö·û´®´¦Àí¡£±¾ÕÂʹÓÃÏ൱ƪ·ù°ïÖúÄúÁ˽âÕýÔò±í´ïʽÒýÇæ´¦Àí×Ö·û´®µÄÔÀí£¬²¢½²ÊÚÈçºÎÀûÓÃÕâЩ֪ʶÊéдÕýÔò±í´ïʽ¡£
Also in this chapter, you'll learn about the fastest cross-browser methods for concatenating and trimming strings, discover how to increase regex performance by reducing backtracking, and pick up plenty of other tips and tricks for efficiently processing strings and regular expressions.
ͨ¹ý±¾ÕÂÄÚÈÝ£¬Äú»¹½«Ñ§µ½¹ØÓÚÁ¬½Ó¡¢ÐÞÕû×Ö·û´®µÄ×î¿ìµÄ¿çä¯ÀÀÆ÷·½·¨£¬Ì½Ë÷ÈçºÎͨ¹ý¼õÉÙ»ØËÝÀ´Ìá¸ßÕýÔò±í´ïʽµÄÐÔÄÜ£¬²¢ÌôÑ¡ÁËһЩ¹ØÓÚ¸ßЧ´¦Àí×Ö·û´®ºÍÕýÔò±í´ïʽµÄ¼¼ÇÉ¡£
String Concatenation ×Ö·
Ïà¹ØÎĵµ£º
C#´úÂëÓëjavaScriptº¯ÊýµÄÏ໥µ÷ÓÃ
ÎÊ£º
1.ÈçºÎÔÚJavaScript·ÃÎÊC#º¯Êý?
2.ÈçºÎÔÚJavaScript·ÃÎÊC#±äÁ¿?
3.ÈçºÎÔÚC#ÖзÃÎÊJavaScriptµÄÒÑÓбäÁ¿?
4.ÈçºÎÔÚC#ÖзÃÎÊJavaScriptº¯Êý?
ÎÊÌâ1´ð°¸ÈçÏ£º
javaScriptº¯ÊýÖÐÖ´ÐÐC#´úÂëÖеĺ¯Êý£º
·½·¨Ò»£º1¡¢Ê×ÏȽ¨Á¢Ò»¸ö°´Å¥£¬ÔÚºǫ́½«µ÷Óûò´¦ÀíµÄÄÚÈÝдÈëbutton_clickÖÐ ......
<script>
//дcookiesº¯Êý ×÷ÕߣºµÔÕñ¿
function
SetCookie(name,value)//Á½¸ö²ÎÊý£¬Ò»¸öÊÇcookieµÄÃû×Ó£¬Ò»¸öÊÇÖµ
{
var Days = 30;
//´Ë cookie ½«±»±£´æ 30 Ìì
var exp = new Date(); //new
Date("December 31, 9998");
  ......
Repaints and Reflows ÖØ»æºÍÖØÅŰæ
Once the browser has downloaded all the components of a page—HTML markup, JavaScript, CSS, images—it parses through the files and creates two internal data structures:
µ±ä¯ÀÀÆ÷ÏÂÔØÍêËùÓÐÒ³ÃæHTML±ê¼Ç£¬JavaScri ......
Conditionals Ìõ¼þ±í´ïʽ
Similar in nature to loops, conditionals determine how execution flows through JavaScript. The traditional argument of whether to use if-else statements or a switch statement applies to JavaScript just as it does to other languages. Since different b ......
Recursion Patterns µÝ¹éģʽ
When you run into a call stack size limit, your first step should be to identify any instances of recursion in the code. To that end, there are two recursive patterns to be aware of. The first is the straightforward recursive pattern represented ......