{"id":254,"date":"2009-03-11T08:20:00","date_gmt":"2009-03-11T12:20:00","guid":{"rendered":""},"modified":"2013-11-29T14:19:11","modified_gmt":"2013-11-29T06:19:11","slug":"javascript%e5%9f%ba%e6%9c%ac%e5%af%b9%e8%b1%a1","status":"publish","type":"post","link":"https:\/\/kyle.ai\/blog\/254.html","title":{"rendered":"JavaScript\u57fa\u672c\u5bf9\u8c61"},"content":{"rendered":"<p>Number \u201c\u6570\u5b57\u201d\u5bf9\u8c61\u3002\u8fd9\u4e2a\u5bf9\u8c61\u7528\u5f97\u5f88\u5c11\uff0c\u4f5c\u8005\u5c31\u4e00\u6b21\u4e5f\u6ca1\u6709\u89c1\u8fc7\u3002\u4e0d\u8fc7\u5c5e\u4e8e\u201cNumber\u201d\u7684\u5bf9\u8c61\uff0c\u4e5f\u5c31\u662f\u201c\u53d8\u91cf\u201d\u5c31\u591a\u4e86\u3002<\/p>\n<p>\u5c5e\u6027<\/p>\n<p>MAX_VALUE \u7528\u6cd5\uff1aNumber.MAX_VALUE\uff1b\u8fd4\u56de\u201c\u6700\u5927\u503c\u201d\u3002<br \/>\nMIN_VALUE \u7528\u6cd5\uff1aNumber.MIN_VALUE\uff1b\u8fd4\u56de\u201c\u6700\u5c0f\u503c\u201d\u3002<br \/>\nNaN \u7528\u6cd5\uff1aNumber.NaN \u6216 NaN\uff1b\u8fd4\u56de\u201cNaN\u201d\u3002\u201cNaN\u201d\uff08\u4e0d\u662f\u6570\u503c\uff09\u5728\u5f88\u65e9\u5c31\u4ecb\u7ecd\u8fc7\u4e86\u3002<br \/>\nNEGATIVE_INFINITY \u7528\u6cd5\uff1aNumber.NEGATIVE_INFINITY\uff1b\u8fd4\u56de\uff1a\u8d1f\u65e0\u7a77\u5927\uff0c\u6bd4\u201c\u6700\u5c0f\u503c\u201d\u8fd8\u5c0f\u7684\u503c\u3002<br \/>\nPOSITIVE_INFINITY \u7528\u6cd5\uff1aNumber.POSITIVE_INFINITY\uff1b\u8fd4\u56de\uff1a\u6b63\u65e0\u7a77\u5927\uff0c\u6bd4\u201c\u6700\u5927\u503c\u201d\u8fd8\u5927\u7684\u503c\u3002<\/p>\n<p>\u65b9\u6cd5<\/p>\n<p>toString() \u7528\u6cd5\uff1a.toString()\uff1b\u8fd4\u56de\uff1a\u5b57\u7b26\u4e32\u5f62\u5f0f\u7684\u6570\u503c\u3002\u5982\uff1a\u82e5 a == 123\uff1b\u5219 a.toString() == \u2019123\u2032\u3002<\/p>\n<p>String \u5b57\u7b26\u4e32\u5bf9\u8c61\u3002\u58f0\u660e\u4e00\u4e2a\u5b57\u7b26\u4e32\u5bf9\u8c61\u6700\u7b80\u5355\u3001\u5feb\u6377\u3001\u6709\u6548\u3001\u5e38\u7528\u7684\u65b9\u6cd5\u5c31\u662f\u76f4\u63a5\u8d4b\u503c\u3002<\/p>\n<p>\u5c5e\u6027<\/p>\n<p>length \u7528\u6cd5\uff1a.length\uff1b\u8fd4\u56de\u8be5\u5b57\u7b26\u4e32\u7684\u957f\u5ea6\u3002<\/p>\n<p>\u65b9\u6cd5<\/p>\n<p>charAt() \u7528\u6cd5\uff1a.charAt()\uff1b\u8fd4\u56de\u8be5\u5b57\u7b26\u4e32\u4f4d\u4e8e\u7b2c\u4f4d\u7684\u5355\u4e2a\u5b57\u7b26\u3002\u6ce8\u610f\uff1a\u5b57\u7b26\u4e32\u4e2d\u7684\u4e00\u4e2a\u5b57\u7b26\u662f\u7b2c 0 \u4f4d\u7684\uff0c\u7b2c\u4e8c\u4e2a\u624d\u662f\u7b2c 1 \u4f4d\u7684\uff0c\u6700\u540e\u4e00\u4e2a\u5b57\u7b26\u662f\u7b2c length \u2013 1 \u4f4d\u7684\u3002<br \/>\ncharCodeAt() \u7528\u6cd5\uff1a.charCodeAt()\uff1b\u8fd4\u56de\u8be5\u5b57\u7b26\u4e32\u4f4d\u4e8e\u7b2c\u4f4d\u7684\u5355\u4e2a\u5b57\u7b26\u7684 ASCII \u7801\u3002<br \/>\nfromCharCode() \u7528\u6cd5\uff1aString.fromCharCode(a, b, c\u2026)\uff1b\u8fd4\u56de\u4e00\u4e2a\u5b57\u7b26\u4e32\uff0c\u8be5\u5b57\u7b26\u4e32\u6bcf\u4e2a\u5b57\u7b26\u7684 ASCII \u7801\u7531 a, b, c\u2026 \u7b49\u6765\u786e\u5b9a\u3002<br \/>\nindexOf() \u7528\u6cd5\uff1a.indexOf([, ])\uff1b\u8be5\u65b9\u6cd5\u4ece\u4e2d\u67e5\u627e\uff08\u5982\u679c\u7ed9\u51fa\u5c31\u5ffd\u7565\u4e4b\u524d\u7684\u4f4d\u7f6e\uff09\uff0c\u5982\u679c\u627e\u5230\u4e86\uff0c\u5c31\u8fd4\u56de\u5b83\u7684\u4f4d\u7f6e\uff0c\u6ca1\u6709\u627e\u5230\u5c31\u8fd4\u56de\u201c-1\u201d\u3002\u6240\u6709\u7684\u201c\u4f4d\u7f6e\u201d\u90fd\u662f\u4ece\u96f6\u5f00\u59cb\u7684\u3002<br \/>\nlastIndexOf() \u7528\u6cd5\uff1a.lastIndexOf([, ])\uff1b\u8ddf indexOf() \u76f8\u4f3c\uff0c\u4e0d\u8fc7\u662f\u4ece\u540e\u8fb9\u5f00\u59cb\u627e\u3002<br \/>\nsplit() \u7528\u6cd5\uff1a.split()\uff1b\u8fd4\u56de\u4e00\u4e2a\u6570\u7ec4\uff0c\u8be5\u6570\u7ec4\u662f\u4ece\u4e2d\u5206\u79bb\u5f00\u6765\u7684\uff0c\u51b3\u5b9a\u4e86\u5206\u79bb\u7684\u5730\u65b9\uff0c\u5b83\u672c\u8eab\u4e0d\u4f1a\u5305\u542b\u5728\u6240\u8fd4\u56de\u7684\u6570\u7ec4\u4e2d\u3002\u4f8b\u5982\uff1a\u20191&amp;2&amp;345&amp;678\u2032.split(\u2018&amp;\u2019)\u8fd4\u56de\u6570\u7ec4\uff1a1,2,345,678\u3002\u5173\u4e8e\u6570\u7ec4\uff0c\u6211\u4eec\u7b49\u4e00\u4e0b\u5c31\u8ba8\u8bba\u3002<br \/>\nsubstring() \u7528\u6cd5\uff1a.substring([, ])\uff1b\u8fd4\u56de\u539f\u5b57\u7b26\u4e32\u7684\u5b50\u5b57\u7b26\u4e32\uff0c\u8be5\u5b57\u7b26\u4e32\u662f\u539f\u5b57\u7b26\u4e32\u4ece\u4f4d\u7f6e\u5230\u4f4d\u7f6e\u7684\u524d\u4e00\u4f4d\u7f6e\u7684\u4e00\u6bb5\u3002 \u2013 = \u8fd4\u56de\u5b57\u7b26\u4e32\u7684\u957f\u5ea6\uff08length\uff09\u3002\u5982\u679c\u6ca1\u6709\u6307\u5b9a\u6216\u6307\u5b9a\u5f97\u8d85\u8fc7\u5b57\u7b26\u4e32\u957f\u5ea6\uff0c\u5219\u5b50\u5b57\u7b26\u4e32\u4ece\u4f4d\u7f6e\u4e00\u76f4\u53d6\u5230\u539f\u5b57\u7b26\u4e32\u5c3e\u3002\u5982\u679c\u6240\u6307\u5b9a\u7684\u4f4d\u7f6e\u4e0d\u80fd\u8fd4\u56de\u5b57\u7b26\u4e32\uff0c\u5219\u8fd4\u56de\u7a7a\u5b57\u7b26\u4e32\u3002<br \/>\nsubstr() \u7528\u6cd5\uff1a.substr([, ])\uff1b\u8fd4\u56de\u539f\u5b57\u7b26\u4e32\u7684\u5b50\u5b57\u7b26\u4e32\uff0c\u8be5\u5b57\u7b26\u4e32\u662f\u539f\u5b57\u7b26\u4e32\u4ece\u4f4d\u7f6e\u5f00\u59cb\uff0c\u957f\u5ea6\u4e3a\u7684\u4e00\u6bb5\u3002\u5982\u679c\u6ca1\u6709\u6307\u5b9a\u6216\u6307\u5b9a\u5f97\u8d85\u8fc7\u5b57\u7b26\u4e32\u957f\u5ea6\uff0c\u5219\u5b50\u5b57\u7b26\u4e32\u4ece\u4f4d\u7f6e\u4e00\u76f4\u53d6\u5230\u539f\u5b57\u7b26\u4e32\u5c3e\u3002\u5982\u679c\u6240\u6307\u5b9a\u7684\u4f4d\u7f6e\u4e0d\u80fd\u8fd4\u56de\u5b57\u7b26\u4e32\uff0c\u5219\u8fd4\u56de\u7a7a\u5b57\u7b26\u4e32\u3002<br \/>\ntoLowerCase() \u7528\u6cd5\uff1a.toLowerCase()\uff1b\u8fd4\u56de\u628a\u539f\u5b57\u7b26\u4e32\u6240\u6709\u5927\u5199\u5b57\u6bcd\u90fd\u53d8\u6210\u5c0f\u5199\u7684\u5b57\u7b26\u4e32\u3002<br \/>\ntoUpperCase() \u7528\u6cd5\uff1a.toUpperCase()\uff1b\u8fd4\u56de\u628a\u539f\u5b57\u7b26\u4e32\u6240\u6709\u5c0f\u5199\u5b57\u6bcd\u90fd\u53d8\u6210\u5927\u5199\u7684\u5b57\u7b26\u4e32\u3002<\/p>\n<p>Array \u6570\u7ec4\u5bf9\u8c61\u3002\u6570\u7ec4\u5bf9\u8c61\u662f\u4e00\u4e2a\u5bf9\u8c61\u7684\u96c6\u5408\uff0c\u91cc\u8fb9\u7684\u5bf9\u8c61\u53ef\u4ee5\u662f\u4e0d\u540c\u7c7b\u578b\u7684\u3002\u6570\u7ec4\u7684\u6bcf\u4e00\u4e2a\u6210\u5458\u5bf9\u8c61\u90fd\u6709\u4e00\u4e2a\u201c\u4e0b\u6807\u201d\uff0c\u7528\u6765\u8868\u793a\u5b83\u5728\u6570\u7ec4\u4e2d\u7684\u4f4d\u7f6e\uff08\u65e2\u7136\u662f\u201c\u4f4d\u7f6e\u201d\uff0c\u5c31\u4e5f\u662f\u4ece\u96f6\u5f00\u59cb\u7684\u5566\uff09\u3002<\/p>\n<p>\u6570\u7ec4\u7684\u5b9a\u4e49\u65b9\u6cd5\uff1a<\/p>\n<p>var= new Array();<\/p>\n<p>\u8fd9\u6837\u5c31\u5b9a\u4e49\u4e86\u4e00\u4e2a\u7a7a\u6570\u7ec4\u3002\u4ee5\u540e\u8981\u6dfb\u52a0\u6570\u7ec4\u5143\u7d20\uff0c\u5c31\u7528\uff1a<\/p>\n<p>[] = \u2026;<\/p>\n<p>\u6ce8\u610f\u8fd9\u91cc\u7684\u65b9\u62ec\u53f7\u4e0d\u662f\u201c\u53ef\u4ee5\u7701\u7565\u201d\u7684\u610f\u601d\uff0c\u6570\u7ec4\u7684\u4e0b\u6807\u8868\u793a\u65b9\u6cd5\u5c31\u662f\u7528\u65b9\u62ec\u53f7\u62ec\u8d77\u6765\u3002<\/p>\n<p>\u5982\u679c\u60f3\u5728\u5b9a\u4e49\u6570\u7ec4\u7684\u65f6\u5019\u76f4\u63a5\u521d\u59cb\u5316\u6570\u636e\uff0c\u8bf7\u7528\uff1a<\/p>\n<p>var= new Array(,,\u2026);<\/p>\n<p>\u4f8b\u5982\uff0cvar myArray = new Array(1, 4.5, \u2018Hi\u2019); \u5b9a\u4e49\u4e86\u4e00\u4e2a\u6570\u7ec4 myArray\uff0c\u91cc\u8fb9\u7684\u5143\u7d20\u662f\uff1amyArray[0] == 1; myArray[1] == 4.5; myArray[2] == \u2018Hi\u2019\u3002<\/p>\n<p>\u4f46\u662f\uff0c\u5982\u679c\u5143\u7d20\u5217\u8868\u4e2d\u53ea\u6709\u4e00\u4e2a\u5143\u7d20\uff0c\u800c\u8fd9\u4e2a\u5143\u7d20\u53c8\u662f\u4e00\u4e2a\u6b63\u6574\u6570\u7684\u8bdd\uff0c\u8fd9\u5c06\u5b9a\u4e49\u4e00\u4e2a\u5305\u542b\u4e2a\u7a7a\u5143\u7d20\u7684\u6570\u7ec4\u3002<\/p>\n<p>\u6ce8\u610f\uff1aJavaScript\u53ea\u6709\u4e00\u7ef4\u6570\u7ec4\uff01\u5343\u4e07\u4e0d\u8981\u7528\u201cArray(3,4)\u201d\u8fd9\u79cd\u611a\u8822\u7684\u65b9\u6cd5\u6765\u5b9a\u4e49 4 x 5 \u7684\u4e8c\u7ef4\u6570\u7ec4\uff0c\u6216\u8005\u7528\u201cmyArray[2,3]\u201d\u8fd9\u79cd\u65b9\u6cd5\u6765\u8fd4\u56de\u201c\u4e8c\u7ef4\u6570\u7ec4\u201d\u4e2d\u7684\u5143\u7d20\u3002\u4efb\u610f\u201cmyArray[&#8230;,3]\u201d\u8fd9\u79cd\u5f62\u5f0f\u7684\u8c03\u7528\u5176\u5b9e\u53ea\u8fd4\u56de\u4e86\u201cmyArray[3]\u201d\u3002\u8981\u4f7f\u7528\u591a\u7ef4\u6570\u7ec4\uff0c\u8bf7\u7528\u8fd9\u79cd\u865a\u62df\u6cd5\uff1a<\/p>\n<p>var myArray = new Array(new Array(), new Array(), new Array(), \u2026);<\/p>\n<p>\u5176\u5b9e\u8fd9\u662f\u4e00\u4e2a\u4e00\u7ef4\u6570\u7ec4\uff0c\u91cc\u8fb9\u7684\u6bcf\u4e00\u4e2a\u5143\u7d20\u53c8\u662f\u4e00\u4e2a\u6570\u7ec4\u3002\u8c03\u7528\u8fd9\u4e2a\u201c\u4e8c\u7ef4\u6570\u7ec4\u201d\u7684\u5143\u7d20\u65f6\uff1amyArray[2][3] = \u2026;<\/p>\n<p>\u5c5e\u6027<\/p>\n<p>length \u7528\u6cd5\uff1a.length\uff1b\u8fd4\u56de\uff1a\u6570\u7ec4\u7684\u957f\u5ea6\uff0c\u5373\u6570\u7ec4\u91cc\u6709\u591a\u5c11\u4e2a\u5143\u7d20\u3002\u5b83\u7b49\u4e8e\u6570\u7ec4\u91cc\u6700\u540e\u4e00\u4e2a\u5143\u7d20\u7684\u4e0b\u6807\u52a0\u4e00\u3002\u6240\u4ee5\uff0c\u60f3\u6dfb\u52a0\u4e00\u4e2a\u5143\u7d20\uff0c\u53ea\u9700\u8981\uff1amyArray[myArray.length] = \u2026\u3002<\/p>\n<p>\u65b9\u6cd5<\/p>\n<p>join() \u7528\u6cd5\uff1a.join()\uff1b\u8fd4\u56de\u4e00\u4e2a\u5b57\u7b26\u4e32\uff0c\u8be5\u5b57\u7b26\u4e32\u628a\u6570\u7ec4\u4e2d\u7684\u5404\u4e2a\u5143\u7d20\u4e32\u8d77\u6765\uff0c\u7528\u7f6e\u4e8e\u5143\u7d20\u4e0e\u5143\u7d20\u4e4b\u95f4\u3002\u8fd9\u4e2a\u65b9\u6cd5\u4e0d\u5f71\u54cd\u6570\u7ec4\u539f\u672c\u7684\u5185\u5bb9\u3002<br \/>\nreverse() \u7528\u6cd5\uff1a.reverse()\uff1b\u4f7f\u6570\u7ec4\u4e2d\u7684\u5143\u7d20\u987a\u5e8f\u53cd\u8fc7\u6765\u3002\u5982\u679c\u5bf9\u6570\u7ec4[1, 2, 3]\u4f7f\u7528\u8fd9\u4e2a\u65b9\u6cd5\uff0c\u5b83\u5c06\u4f7f\u6570\u7ec4\u53d8\u6210\uff1a[3, 2, 1]\u3002<br \/>\nslice() \u7528\u6cd5\uff1a.slice([, ])\uff1b\u8fd4\u56de\u4e00\u4e2a\u6570\u7ec4\uff0c\u8be5\u6570\u7ec4\u662f\u539f\u6570\u7ec4\u7684\u5b50\u96c6\uff0c\u59cb\u4e8e\uff0c\u7ec8\u4e8e\u3002\u5982\u679c\u4e0d\u7ed9\u51fa\uff0c\u5219\u5b50\u96c6\u4e00\u76f4\u53d6\u5230\u539f\u6570\u7ec4\u7684\u7ed3\u5c3e\u3002<br \/>\nsort() \u7528\u6cd5\uff1a.sort([])\uff1b\u4f7f\u6570\u7ec4\u4e2d\u7684\u5143\u7d20\u6309\u7167\u4e00\u5b9a\u7684\u987a\u5e8f\u6392\u5217\u3002\u5982\u679c\u4e0d\u6307\u5b9a\uff0c\u5219\u6309\u5b57\u6bcd\u987a\u5e8f\u6392\u5217\u3002\u5728\u8fd9\u79cd\u60c5\u51b5\u4e0b\uff0c80 \u662f\u6bd4 9 \u6392\u5f97\u524d\u7684\u3002\u5982\u679c\u6307\u5b9a\uff0c\u5219\u6309\u6240\u6307\u5b9a\u7684\u6392\u5e8f\u65b9\u6cd5\u6392\u5e8f\u3002\u6bd4\u8f83\u96be\u8bb2\u8ff0\uff0c\u8fd9\u91cc\u53ea\u5c06\u4e00\u4e9b\u6709\u7528\u7684\u4ecb\u7ecd\u7ed9\u5927\u5bb6\u3002<\/p>\n<p>\u6309\u5347\u5e8f\u6392\u5217\u6570\u5b57\uff1a<\/p>\n<p>function sortMethod(a, b) {<br \/>\nreturn a \u2013 b;<br \/>\n}<\/p>\n<p>myArray.sort(sortMethod);<\/p>\n<p>\u6309\u964d\u5e8f\u6392\u5217\u6570\u5b57\uff1a\u628a\u4e0a\u9762\u7684\u201ca \u2013 b\u201d\u8be5\u6210\u201cb \u2013 a\u201d\u3002<\/p>\n<p>\u6709\u5173\u51fd\u6570\uff0c\u8bf7\u770b\u4e0b\u9762\u3002<\/p>\n<p>Math \u201c\u6570\u5b66\u201d\u5bf9\u8c61\uff0c\u63d0\u4f9b\u5bf9\u6570\u636e\u7684\u6570\u5b66\u8ba1\u7b97\u3002\u4e0b\u9762\u6240\u63d0\u5230\u7684\u5c5e\u6027\u548c\u65b9\u6cd5\uff0c\u4e0d\u518d\u8be6\u7ec6\u8bf4\u660e\u201c\u7528\u6cd5\u201d\uff0c\u5927\u5bb6\u5728\u4f7f\u7528\u7684\u65f6\u5019\u8bb0\u4f4f\u7528\u201cMath.\u201d\u8fd9\u79cd\u683c\u5f0f\u3002<\/p>\n<p>\u5c5e\u6027<\/p>\n<p>E \u8fd4\u56de\u5e38\u6570 e (2.718281828\u2026)\u3002<br \/>\nLN2 \u8fd4\u56de 2 \u7684\u81ea\u7136\u5bf9\u6570 (ln 2)\u3002<br \/>\nLN10 \u8fd4\u56de 10 \u7684\u81ea\u7136\u5bf9\u6570 (ln 10)\u3002<br \/>\nLOG2E \u8fd4\u56de\u4ee5 2 \u4e3a\u4f4e\u7684 e \u7684\u5bf9\u6570 (log2e)\u3002<br \/>\nLOG10E \u8fd4\u56de\u4ee5 10 \u4e3a\u4f4e\u7684 e \u7684\u5bf9\u6570 (log10e)\u3002<br \/>\nPI \u8fd4\u56de\u03c0\uff083.1415926535\u2026)\u3002<br \/>\nSQRT1_2 \u8fd4\u56de 1\/2 \u7684\u5e73\u65b9\u6839\u3002<br \/>\nSQRT2 \u8fd4\u56de 2 \u7684\u5e73\u65b9\u6839\u3002<\/p>\n<p>\u65b9\u6cd5<\/p>\n<p>abs(x) \u8fd4\u56de x \u7684\u7edd\u5bf9\u503c\u3002<br \/>\nacos(x) \u8fd4\u56de x \u7684\u53cd\u4f59\u5f26\u503c\uff08\u4f59\u5f26\u503c\u7b49\u4e8e x \u7684\u89d2\u5ea6\uff09\uff0c\u7528\u5f27\u5ea6\u8868\u793a\u3002<br \/>\nasin(x) \u8fd4\u56de x \u7684\u53cd\u6b63\u5f26\u503c\u3002<br \/>\natan(x) \u8fd4\u56de x \u7684\u53cd\u6b63\u5207\u503c\u3002<br \/>\natan2(x, y) \u8fd4\u56de\u590d\u5e73\u9762\u5185\u70b9(x, y)\u5bf9\u5e94\u7684\u590d\u6570\u7684\u5e45\u89d2\uff0c\u7528\u5f27\u5ea6\u8868\u793a\uff0c\u5176\u503c\u5728 -\u03c0 \u5230 \u03c0 \u4e4b\u95f4\u3002<br \/>\nceil(x) \u8fd4\u56de\u5927\u4e8e\u7b49\u4e8e x \u7684\u6700\u5c0f\u6574\u6570\u3002<br \/>\ncos(x) \u8fd4\u56de x \u7684\u4f59\u5f26\u3002<br \/>\nexp(x) \u8fd4\u56de e \u7684 x \u6b21\u5e42 (ex)\u3002<br \/>\nfloor(x) \u8fd4\u56de\u5c0f\u4e8e\u7b49\u4e8e x \u7684\u6700\u5927\u6574\u6570\u3002<br \/>\nlog(x) \u8fd4\u56de x \u7684\u81ea\u7136\u5bf9\u6570 (ln x)\u3002<br \/>\nmax(a, b) \u8fd4\u56de a, b \u4e2d\u8f83\u5927\u7684\u6570\u3002<br \/>\nmin(a, b) \u8fd4\u56de a, b \u4e2d\u8f83\u5c0f\u7684\u6570\u3002<br \/>\npow(n, m) \u8fd4\u56de n \u7684 m \u6b21\u5e42 (nm)\u3002<br \/>\nrandom() \u8fd4\u56de\u5927\u4e8e 0 \u5c0f\u4e8e 1 \u7684\u4e00\u4e2a\u968f\u673a\u6570\u3002<br \/>\nround(x) \u8fd4\u56de x \u56db\u820d\u4e94\u5165\u540e\u7684\u503c\u3002<br \/>\nsin(x) \u8fd4\u56de x \u7684\u6b63\u5f26\u3002<br \/>\nsqrt(x) \u8fd4\u56de x \u7684\u5e73\u65b9\u6839\u3002<br \/>\ntan(x) \u8fd4\u56de x \u7684\u6b63\u5207\u3002<\/p>\n<p>Date \u65e5\u671f\u5bf9\u8c61\u3002\u8fd9\u4e2a\u5bf9\u8c61\u53ef\u4ee5\u50a8\u5b58\u4efb\u610f\u4e00\u4e2a\u65e5\u671f\uff0c\u4ece 0001 \u5e74\u5230 9999 \u5e74\uff0c\u5e76\u4e14\u53ef\u4ee5\u7cbe\u786e\u5230\u6beb\u79d2\u6570\uff081\/1000 \u79d2\uff09\u3002\u5728\u5185\u90e8\uff0c\u65e5\u671f\u5bf9\u8c61\u662f\u4e00\u4e2a\u6574\u6570\uff0c\u5b83\u662f\u4ece 1970 \u5e74 1 \u6708 1 \u65e5\u96f6\u65f6\u6b63\u5f00\u59cb\u8ba1\u7b97\u5230\u65e5\u671f\u5bf9\u8c61\u6240\u6307\u7684\u65e5\u671f\u7684\u6beb\u79d2\u6570\u3002\u5982\u679c\u6240\u6307\u65e5\u671f\u6bd4 1970 \u5e74\u65e9\uff0c\u5219\u5b83\u662f\u4e00\u4e2a\u8d1f\u6570\u3002\u6240\u6709\u65e5\u671f\u65f6\u95f4\uff0c\u5982\u679c\u4e0d\u6307\u5b9a\u65f6\u533a\uff0c\u90fd\u91c7\u7528\u201cUTC\u201d\uff08\u4e16\u754c\u65f6\uff09\u65f6\u533a\uff0c\u5b83\u4e0e\u201cGMT\u201d\uff08\u683c\u6797\u5a01\u6cbb\u65f6\u95f4\uff09\u5728\u6570\u503c\u4e0a\u662f\u4e00\u6837\u7684\u3002<\/p>\n<p>\u5b9a\u4e49\u4e00\u4e2a\u65e5\u671f\u5bf9\u8c61\uff1a<\/p>\n<p>var d = new Date;<\/p>\n<p>\u8fd9\u4e2a\u65b9\u6cd5\u4f7f d \u6210\u4e3a\u65e5\u671f\u5bf9\u8c61\uff0c\u5e76\u4e14\u5df2\u6709\u521d\u59cb\u503c\uff1a\u5f53\u524d\u65f6\u95f4\u3002\u5982\u679c\u8981\u81ea\u5b9a\u521d\u59cb\u503c\uff0c\u53ef\u4ee5\u7528\uff1a<\/p>\n<p>var d = new Date(99, 10, 1); \/\/99 \u5e74 10 \u6708 1 \u65e5<br \/>\nvar d = new Date(\u2018Oct 1, 1999\u2032); \/\/99 \u5e74 10 \u6708 1 \u65e5<\/p>\n<p>\u7b49\u7b49\u65b9\u6cd5\u3002\u6700\u597d\u7684\u65b9\u6cd5\u5c31\u662f\u7528\u4e0b\u9762\u4ecb\u7ecd\u7684\u201c\u65b9\u6cd5\u201d\u6765\u4e25\u683c\u7684\u5b9a\u4e49\u65f6\u95f4\u3002<\/p>\n<p>\u65b9\u6cd5<\/p>\n<p>\u4ee5\u4e0b\u6709\u5f88\u591a\u201cg\/set[UTC]XXX\u201d\u8fd9\u6837\u7684\u65b9\u6cd5\uff0c\u5b83\u8868\u793a\u65e2\u6709\u201cgetXXX\u201d\u65b9\u6cd5\uff0c\u53c8\u6709\u201csetXXX\u201d\u65b9\u6cd5\u3002\u201cget\u201d\u662f\u83b7\u5f97\u67d0\u4e2a\u6570\u503c\uff0c\u800c\u201cset\u201d\u662f\u8bbe\u5b9a\u67d0\u4e2a\u6570\u503c\u3002\u5982\u679c\u5e26\u6709\u201cUTC\u201d\u5b57\u6bcd\uff0c\u5219\u8868\u793a\u83b7\u5f97\/\u8bbe\u5b9a\u7684\u6570\u503c\u662f\u57fa\u4e8e UTC \u65f6\u95f4\u7684\uff0c\u6ca1\u6709\u5219\u8868\u793a\u57fa\u4e8e\u672c\u5730\u65f6\u95f4\u6216\u6d4f\u89c8\u671f\u9ed8\u8ba4\u65f6\u95f4\u7684\u3002<\/p>\n<p>\u5982\u65e0\u8bf4\u660e\uff0c\u65b9\u6cd5\u7684\u4f7f\u7528\u683c\u5f0f\u4e3a\uff1a\u201c.\u201d\uff0c\u4e0b\u540c\u3002<\/p>\n<p>g\/set[UTC]FullYear() \u8fd4\u56de\/\u8bbe\u7f6e\u5e74\u4efd\uff0c\u7528\u56db\u4f4d\u6570\u8868\u793a\u3002\u5982\u679c\u4f7f\u7528\u201cx.set[UTC]FullYear(99)\u201d\uff0c\u5219\u5e74\u4efd\u88ab\u8bbe\u5b9a\u4e3a 0099 \u5e74\u3002<br \/>\ng\/set[UTC]Year() \u8fd4\u56de\/\u8bbe\u7f6e\u5e74\u4efd\uff0c\u7528\u4e24\u4f4d\u6570\u8868\u793a\u3002\u8bbe\u5b9a\u7684\u65f6\u5019\u6d4f\u89c8\u5668\u81ea\u52a8\u52a0\u4e0a\u201c19\u201d\u5f00\u5934\uff0c\u6545\u4f7f\u7528\u201cx.set[UTC]Year(00)\u201d\u628a\u5e74\u4efd\u8bbe\u5b9a\u4e3a 1900 \u5e74\u3002<br \/>\ng\/set[UTC]Month() \u8fd4\u56de\/\u8bbe\u7f6e\u6708\u4efd\u3002<br \/>\ng\/set[UTC]Date() \u8fd4\u56de\/\u8bbe\u7f6e\u65e5\u671f\u3002<br \/>\ng\/set[UTC]Day() \u8fd4\u56de\/\u8bbe\u7f6e\u661f\u671f\uff0c0 \u8868\u793a\u661f\u671f\u5929\u3002<br \/>\ng\/set[UTC]Hours() \u8fd4\u56de\/\u8bbe\u7f6e\u5c0f\u65f6\u6570\uff0c24\u5c0f\u65f6\u5236\u3002<br \/>\ng\/set[UTC]Minutes() \u8fd4\u56de\/\u8bbe\u7f6e\u5206\u949f\u6570\u3002<br \/>\ng\/set[UTC]Seconds() \u8fd4\u56de\/\u8bbe\u7f6e\u79d2\u949f\u6570\u3002<br \/>\ng\/set[UTC]Milliseconds() \u8fd4\u56de\/\u8bbe\u7f6e\u6beb\u79d2\u6570\u3002<br \/>\ng\/setTime() \u8fd4\u56de\/\u8bbe\u7f6e\u65f6\u95f4\uff0c\u8be5\u65f6\u95f4\u5c31\u662f\u65e5\u671f\u5bf9\u8c61\u7684\u5185\u90e8\u5904\u7406\u65b9\u6cd5\uff1a\u4ece 1970 \u5e74 1 \u6708 1 \u65e5\u96f6\u65f6\u6b63\u5f00\u59cb\u8ba1\u7b97\u5230\u65e5\u671f\u5bf9\u8c61\u6240\u6307\u7684\u65e5\u671f\u7684\u6beb\u79d2\u6570\u3002\u5982\u679c\u8981\u4f7f\u67d0\u65e5\u671f\u5bf9\u8c61\u6240\u6307\u7684\u65f6\u95f4\u63a8\u8fdf 1 \u5c0f\u65f6\uff0c\u5c31\u7528\uff1a\u201cx.setTime(x.getTime() + 60 * 60 * 1000);\u201d\uff08\u4e00\u5c0f\u65f6 60 \u5206\uff0c\u4e00\u5206 60 \u79d2\uff0c\u4e00\u79d2 1000 \u6beb\u79d2\uff09\u3002<br \/>\ngetTimezoneOffset() \u8fd4\u56de\u65e5\u671f\u5bf9\u8c61\u91c7\u7528\u7684\u65f6\u533a\u4e0e\u683c\u6797\u5a01\u6cbb\u65f6\u95f4\u6240\u5dee\u7684\u5206\u949f\u6570\u3002\u5728\u683c\u6797\u5a01\u6cbb\u4e1c\u65b9\u7684\u5e02\u533a\uff0c\u8be5\u503c\u4e3a\u8d1f\uff0c\u4f8b\u5982\uff1a\u4e2d\u56fd\u65f6\u533a\uff08GMT+0800\uff09\u8fd4\u56de\u201c-480\u201d\u3002<br \/>\ntoString() \u8fd4\u56de\u4e00\u4e2a\u5b57\u7b26\u4e32\uff0c\u63cf\u8ff0\u65e5\u671f\u5bf9\u8c61\u6240\u6307\u7684\u65e5\u671f\u3002\u8fd9\u4e2a\u5b57\u7b26\u4e32\u7684\u683c\u5f0f\u7c7b\u4f3c\u4e8e\uff1a\u201cFri Jul 21 15:43:46 UTC+0800 2000\u201d\u3002<br \/>\ntoLocaleString() \u8fd4\u56de\u4e00\u4e2a\u5b57\u7b26\u4e32\uff0c\u63cf\u8ff0\u65e5\u671f\u5bf9\u8c61\u6240\u6307\u7684\u65e5\u671f\uff0c\u7528\u672c\u5730\u65f6\u95f4\u8868\u793a\u683c\u5f0f\u3002\u5982\uff1a\u201c2000-07-21 15:43:46\u201d\u3002<br \/>\ntoGMTString() \u8fd4\u56de\u4e00\u4e2a\u5b57\u7b26\u4e32\uff0c\u63cf\u8ff0\u65e5\u671f\u5bf9\u8c61\u6240\u6307\u7684\u65e5\u671f\uff0c\u7528 GMT \u683c\u5f0f\u3002<br \/>\ntoUTCString() \u8fd4\u56de\u4e00\u4e2a\u5b57\u7b26\u4e32\uff0c\u63cf\u8ff0\u65e5\u671f\u5bf9\u8c61\u6240\u6307\u7684\u65e5\u671f\uff0c\u7528 UTC \u683c\u5f0f\u3002<br \/>\nparse() \u7528\u6cd5\uff1aDate.parse()\uff1b\u8fd4\u56de\u8be5\u65e5\u671f\u5bf9\u8c61\u7684\u5185\u90e8\u8868\u8fbe\u65b9\u5f0f\u3002<\/p>\n<p>\u5168\u5c40\u5bf9\u8c61<\/p>\n<p>\u5168\u5c40\u5bf9\u8c61\u4ece\u4e0d\u73b0\u5f62\uff0c\u5b83\u53ef\u4ee5\u8bf4\u662f\u865a\u62df\u51fa\u6765\u7684\uff0c\u76ee\u7684\u5728\u4e8e\u628a\u5168\u5c40\u51fd\u6570\u201c\u5bf9\u8c61\u5316\u201d\u3002\u5728 Microsoft JScript \u8bed\u8a00\u53c2\u8003\u4e2d\uff0c\u5b83\u53eb\u505a\u201cGlobal \u5bf9\u8c61\u201d\uff0c\u4f46\u662f\u5f15\u7528\u5b83\u7684\u65b9\u6cd5\u548c\u5c5e\u6027\u4ece\u6765\u4e0d\u7528\u201cGlobal.xxx\u201d\uff08\u51b5\u4e14\u8fd9\u6837\u505a\u4f1a\u51fa\u9519\uff09\uff0c\u800c\u76f4\u63a5\u7528\u201cxxx\u201d\u3002<\/p>\n<p>\u5c5e\u6027<\/p>\n<p>NaN \u4e00\u65e9\u5c31\u8bf4\u8fc7\u4e86\u3002<\/p>\n<p>\u65b9\u6cd5<\/p>\n<p>eval() \u628a\u62ec\u53f7\u5185\u7684\u5b57\u7b26\u4e32\u5f53\u4f5c\u6807\u51c6\u8bed\u53e5\u6216\u8868\u8fbe\u5f0f\u6765\u8fd0\u884c\u3002<br \/>\nisFinite() \u5982\u679c\u62ec\u53f7\u5185\u7684\u6570\u5b57\u662f\u201c\u6709\u9650\u201d\u7684\uff08\u4ecb\u4e8e Number.MIN_VALUE \u548c Number.MAX_VALUE \u4e4b\u95f4\uff09\u5c31\u8fd4\u56de true\uff1b\u5426\u5219\u8fd4\u56de false\u3002<br \/>\nisNaN() \u5982\u679c\u62ec\u53f7\u5185\u7684\u503c\u662f\u201cNaN\u201d\u5219\u8fd4\u56de true \u5426\u5219\u8fd4\u56de false\u3002<br \/>\nparseInt() \u8fd4\u56de\u628a\u62ec\u53f7\u5185\u7684\u5185\u5bb9\u8f6c\u6362\u6210\u6574\u6570\u4e4b\u540e\u7684\u503c\u3002\u5982\u679c\u62ec\u53f7\u5185\u662f\u5b57\u7b26\u4e32\uff0c\u5219\u5b57\u7b26\u4e32\u5f00\u5934\u7684\u6570\u5b57\u90e8\u5206\u88ab\u8f6c\u6362\u6210\u6574\u6570\uff0c\u5982\u679c\u4ee5\u5b57\u6bcd\u5f00\u5934\uff0c\u5219\u8fd4\u56de\u201cNaN\u201d\u3002<br \/>\nparseFloat() \u8fd4\u56de\u628a\u62ec\u53f7\u5185\u7684\u5b57\u7b26\u4e32\u8f6c\u6362\u6210\u6d6e\u70b9\u6570\u4e4b\u540e\u7684\u503c\uff0c\u5b57\u7b26\u4e32\u5f00\u5934\u7684\u6570\u5b57\u90e8\u5206\u88ab\u8f6c\u6362\u6210\u6d6e\u70b9\u6570\uff0c\u5982\u679c\u4ee5\u5b57\u6bcd\u5f00\u5934\uff0c\u5219\u8fd4\u56de\u201cNaN\u201d\u3002<br \/>\ntoString() \u7528\u6cd5\uff1a.toString()\uff1b\u628a\u5bf9\u8c61\u8f6c\u6362\u6210\u5b57\u7b26\u4e32\u3002\u5982\u679c\u5728\u62ec\u53f7\u4e2d\u6307\u5b9a\u4e00\u4e2a\u6570\u503c\uff0c\u5219\u8f6c\u6362\u8fc7\u7a0b\u4e2d\u6240\u6709\u6570\u503c\u8f6c\u6362\u6210\u7279\u5b9a\u8fdb\u5236\u3002<br \/>\nescape() \u8fd4\u56de\u62ec\u53f7\u4e2d\u7684\u5b57\u7b26\u4e32\u7ecf\u8fc7\u7f16\u7801\u540e\u7684\u65b0\u5b57\u7b26\u4e32\u3002\u8be5\u7f16\u7801\u5e94\u7528\u4e8e URL\uff0c\u4e5f\u5c31\u662f\u628a\u7a7a\u683c\u5199\u6210\u201c%20\u201d\u8fd9\u79cd\u683c\u5f0f\u3002\u201c+\u201d\u4e0d\u88ab\u7f16\u7801\uff0c\u5982\u679c\u8981\u201c+\u201d\u4e5f\u88ab\u7f16\u7801\uff0c\u8bf7\u7528\uff1aescape(\u2018\u2026\u2019, 1)\u3002<br \/>\nunescape() \u662f escape() \u7684\u53cd\u8fc7\u7a0b\u3002\u89e3\u7f16\u62ec\u53f7\u4e2d\u5b57\u7b26\u4e32\u6210\u4e3a\u4e00\u822c\u5b57\u7b26\u4e32\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Number \u201c\u6570\u5b57\u201d\u5bf9\u8c61\u3002\u8fd9\u4e2a\u5bf9\u8c61\u7528\u5f97\u5f88\u5c11\uff0c\u4f5c\u8005\u5c31\u4e00\u6b21\u4e5f\u6ca1\u6709\u89c1\u8fc7\u3002\u4e0d\u8fc7\u5c5e\u4e8e\u201cNumber\u201d\u7684\u5bf9\u8c61\uff0c\u4e5f\u5c31\u662f\u201c\u53d8 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6],"tags":[],"class_list":["post-254","post","type-post","status-publish","format-standard","hentry","category-code_related"],"_links":{"self":[{"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/posts\/254","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/comments?post=254"}],"version-history":[{"count":1,"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/posts\/254\/revisions"}],"predecessor-version":[{"id":5319,"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/posts\/254\/revisions\/5319"}],"wp:attachment":[{"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/media?parent=254"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/categories?post=254"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/tags?post=254"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}