{"id":672,"date":"2009-03-13T18:03:06","date_gmt":"2009-03-13T10:03:06","guid":{"rendered":"http:\/\/fdream.net\/blog\/article\/672.aspx"},"modified":"2009-03-13T18:03:23","modified_gmt":"2009-03-13T10:03:23","slug":"%e4%b8%ba%e4%bb%80%e4%b9%88JavaScript%e4%b8%ad%e6%ad%a3%e5%88%99%e8%a1%a8%e8%be%be%e5%bc%8f%e7%9a%84test%e6%96%b9%e6%b3%95%e4%bc%9a%e5%87%ba%e9%94%99%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/fdream.net\/blog\/article\/672","title":{"rendered":"\u4e3a\u4ec0\u4e48JavaScript\u4e2d\u6b63\u5219\u8868\u8fbe\u5f0f\u7684test\u65b9\u6cd5\u4f1a\u51fa\u9519\uff1f"},"content":{"rendered":"<p>\u4e00\u6bb5\u8fd9\u6837\u7684JavaScript\u4ee3\u7801\uff0c\u731c\u731c\u7ed3\u679c\u5982\u4f55\uff1f<\/p>\n<p><pre lang=\"javascript\">\nvar i = 0, m = 20, a = [], r = \/^\\d+$\/g;\nfor(i = 0; i &lt; m; i++){\n    a.push('' + i);\n}\n\nm = a.length;\nfor(i = 0; i &lt; m; i++){\n    if(r.test(a[i])){\n        document.write(a[i] + 'true&lt;br \/&gt;');\n    }\n    else{\n        document.write(a[i] + 'false&lt;br \/&gt;');\n    }\n}\n<\/pre>\n<\/p>\n<p>\u4e5f\u8bb8\u4f60\u671f\u5f85\u7684\u7ed3\u679c\u5e94\u8be5\u5168\u662ftrue\uff0c\u53ef\u662f\u5b9e\u9645\u7ed3\u679c\u5462\uff1ftrue\u548cfalse\u4ea4\u66ff\u51fa\u73b0\uff0c0\u662ftrue\uff0c1\u662ffalse\uff0c2\u662ftrue\uff0c3\u662ffalse\u2026\u2026\u662f\u4e0d\u662f\u5f88\u6000\u7591\uff1f\u5176\u5b9e\u4ed4\u7ec6\u770b\u4e00\u4e0b\uff0c\u90a3\u4e2a\u6b63\u5219\u8868\u8fbe\u5f0f\u591a\u4e86\u4e2a\u5168\u5c40\u9009\u9879\u201cg\u201d\uff0c\u53bb\u6389\u5c31\u597d\u4e86\u3002<\/p>\n<p>\u53ef\u662f\u4e3a\u4ec0\u4e48\u6709\u201cg\u201d\u5c31\u4f1a\u51fa\u9519\u5462\uff1f<\/p>\n<p>\u539f\u56e0\u5176\u5b9e\u5f88\u7b80\u5355\uff0c\u5f53\u4e00\u4e2a\u6a21\u5f0f\u5177\u6709\u5168\u5c40\u9009\u9879\u65f6\uff0c\u548cexec\u4e00\u6837\uff0c\u6bcf\u6b21test\u90fd\u4f1a\u4fdd\u7559\u4e0a\u6b21\u5339\u914d\u7684\u4f4d\u7f6e\u2014\u2014\u5373lastIndex\u3002\u5f88\u663e\u7136\uff0c\u5f53\u7b2c\u4e00\u6b21\u5339\u914d\u4e4b\u540e\uff0c\u7b2c\u4e8c\u6b21\u5339\u914d\u65f6\u7684lastIndex\u5df2\u7ecf\u5230\u4e86\u5b57\u7b26\u4e32\u672b\u5c3e\uff0c\u5c3d\u7ba1\u8fd9\u4e2a\u65f6\u5019\u5b57\u7b26\u4e32\u5df2\u7ecf\u662f\u4e00\u4e2a\u65b0\u7684\u5b57\u7b26\u4e32\u4e86\uff0c\u4f46\u662f\u8fd9\u4e2alastIndex\u7684\u4f4d\u7f6e\u5e76\u6ca1\u6709\u91cd\u65b0\u521d\u59cb\u5316\uff0c\u6240\u4ee5\u4f1a\u4ece\u672b\u5c3e\u5f00\u59cb\u5339\u914d\u2014\u2014\u5f53\u7136\u4f1a\u5339\u914d\u5931\u8d25\u4e86\u3002<\/p>\n<p>\u89e3\u51b3\u65b9\u6848\u6709\u4e24\u79cd\uff1a<\/p>\n<ul style=\"list-style-type:decimal\">\n<li>\u53bb\u6389\u6b63\u5219\u8868\u8fbe\u5f0f\u540e\u9762\u7684g\uff1b<\/li>\n<li>\u6bcf\u6b21\u5b8c\u6210\u5339\u914d\u4e4b\u540e\u91cd\u7f6e\u6a21\u5f0f\u7684lastIndex\u5c5e\u6027\uff1b<\/li>\n<\/ul>\n<p>\u4f7f\u7528\u91cd\u7f6elastIndex\u7684\u4ee3\u7801\uff1a<\/p>\n<p><pre lang=\"javascript\">\nvar i = 0, m = 20, a = [], r = \/^\\d+$\/g;\nfor(i = 0; i &lt; m; i++){\n    a.push('' + i);\n}\n\nm = a.length;\nfor(i = 0; i &lt; m; i++){\n    if(r.test(a[i])){\n        document.write(a[i] + 'true&lt;br \/&gt;');\n    }\n    else{\n        document.write(a[i] + 'false&lt;br \/&gt;');\n    }\n    r.lastIndex = 0;\n}\n<\/pre>\n<\/p>\n<p>OK~<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4e00\u6bb5\u8fd9\u6837\u7684JavaScript\u4ee3\u7801\uff0c\u731c\u731c\u7ed3\u679c\u5982\u4f55\uff1f var i = 0, m = 20, a = [], r = \/^\\d+$\/g; for(i = 0; i &lt; m; i++){ a.push(&#8221; + i); } m = a.length; for(i = 0; i &lt; m; i++){ if(r.test(a[i])){ document.write(a[i] + &#8216;true&lt;br \/&gt;&#8217;); } else{ document.write(a[i] + &#8216;false&lt;br \/&gt;&#8217;); } } \u4e5f\u8bb8\u4f60\u671f\u5f85\u7684\u7ed3\u679c\u5e94\u8be5\u5168\u662ftrue\uff0c\u53ef\u662f\u5b9e\u9645\u7ed3\u679c\u5462\uff1ftrue\u548cfalse\u4ea4\u66ff\u51fa\u73b0\uff0c0\u662ftrue\uff0c1\u662ffalse\uff0c2\u662ftrue\uff0c3\u662ffalse\u2026\u2026\u662f\u4e0d\u662f\u5f88\u6000\u7591\uff1f\u5176\u5b9e\u4ed4\u7ec6\u770b\u4e00\u4e0b\uff0c\u90a3\u4e2a\u6b63\u5219\u8868\u8fbe\u5f0f\u591a\u4e86\u4e2a\u5168\u5c40\u9009\u9879\u201cg\u201d\uff0c\u53bb\u6389\u5c31\u597d\u4e86\u3002 \u53ef\u662f\u4e3a\u4ec0\u4e48\u6709\u201cg\u201d\u5c31\u4f1a\u51fa\u9519\u5462\uff1f \u539f\u56e0\u5176\u5b9e\u5f88\u7b80\u5355\uff0c\u5f53\u4e00\u4e2a\u6a21\u5f0f\u5177\u6709\u5168\u5c40\u9009\u9879\u65f6\uff0c\u548cexec\u4e00\u6837\uff0c\u6bcf\u6b21test\u90fd\u4f1a\u4fdd\u7559\u4e0a\u6b21\u5339\u914d\u7684\u4f4d\u7f6e\u2014\u2014\u5373lastIndex\u3002\u5f88\u663e\u7136\uff0c\u5f53\u7b2c\u4e00\u6b21\u5339\u914d\u4e4b\u540e\uff0c\u7b2c\u4e8c\u6b21\u5339\u914d\u65f6\u7684lastIndex\u5df2\u7ecf\u5230\u4e86\u5b57\u7b26\u4e32\u672b\u5c3e\uff0c\u5c3d\u7ba1\u8fd9\u4e2a\u65f6\u5019\u5b57\u7b26\u4e32\u5df2\u7ecf\u662f\u4e00\u4e2a\u65b0\u7684\u5b57\u7b26\u4e32\u4e86\uff0c\u4f46\u662f\u8fd9\u4e2alastIndex\u7684\u4f4d\u7f6e\u5e76\u6ca1\u6709\u91cd\u65b0\u521d\u59cb\u5316\uff0c\u6240\u4ee5\u4f1a\u4ece\u672b\u5c3e\u5f00\u59cb\u5339\u914d\u2014\u2014\u5f53\u7136\u4f1a\u5339\u914d\u5931\u8d25\u4e86\u3002 \u89e3\u51b3\u65b9\u6848\u6709\u4e24\u79cd\uff1a \u53bb\u6389\u6b63\u5219\u8868\u8fbe\u5f0f\u540e\u9762\u7684g\uff1b \u6bcf\u6b21\u5b8c\u6210\u5339\u914d\u4e4b\u540e\u91cd\u7f6e\u6a21\u5f0f\u7684lastIndex\u5c5e\u6027\uff1b \u4f7f\u7528\u91cd\u7f6elastIndex\u7684\u4ee3\u7801\uff1a &hellip; <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[104,305],"class_list":["post-672","post","type-post","status-publish","format-standard","hentry","category-coding","tag-JavaScript","tag-305"],"views":10026,"_links":{"self":[{"href":"https:\/\/fdream.net\/blog\/wp-json\/wp\/v2\/posts\/672","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fdream.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fdream.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fdream.net\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fdream.net\/blog\/wp-json\/wp\/v2\/comments?post=672"}],"version-history":[{"count":0,"href":"https:\/\/fdream.net\/blog\/wp-json\/wp\/v2\/posts\/672\/revisions"}],"wp:attachment":[{"href":"https:\/\/fdream.net\/blog\/wp-json\/wp\/v2\/media?parent=672"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fdream.net\/blog\/wp-json\/wp\/v2\/categories?post=672"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fdream.net\/blog\/wp-json\/wp\/v2\/tags?post=672"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}