{"id":1924,"date":"2023-03-25T14:26:38","date_gmt":"2023-03-25T06:26:38","guid":{"rendered":""},"modified":"2023-03-25T14:26:38","modified_gmt":"2023-03-25T06:26:38","slug":"ES6 \u5b57\u7b26\u4e32","status":"publish","type":"post","link":"https:\/\/bianchenghao6.com\/1924.html","title":{"rendered":"ES6 \u5b57\u7b26\u4e32"},"content":{"rendered":"
\n
\u4f7f\u7528\u5b57\u7b26\u4e32\u6587\u5b57<\/span> <\/code>\n <\/div>\n <\/code>\n <\/div>\n <\/code>\n <\/div>\n <\/code>\n <\/div>\n <\/code>\n <\/div>\n <\/code>\n <\/div>\n <\/code>\n <\/div>\n <\/code>\n <\/div>\n <\/code>\n <\/div>\n <\/code>\n <\/div>\n <\/code>\n <\/div>\n <\/code>\n <\/div>\n searchValue: \u662f\u8fd9\u4e2a\u65b9\u6cd5\u7684\u5fc5\u9700\u53c2\u6570\u3002\u5b83\u5305\u62ec\u8981\u5728\u5b57\u7b26\u4e32\u5f00\u5934\u641c\u7d22\u7684\u5b57\u7b26\u3002<\/span> <\/code>\n <\/div>\n <\/code>\n <\/div>\n <\/code>\n <\/div>\n searchValue: \u662f\u5fc5\u987b\u7684\u53c2\u6570\uff0c\u4ee3\u8868\u5b57\u7b26\u4e32\u672b\u5c3e\u8981\u641c\u7d22\u7684\u5b57\u7b26\u3002<\/span> <\/code>\n <\/div>\n <\/code>\n <\/div>\n <\/code>\n <\/div>\n searchValue: \u8fd9\u662f\u4e00\u4e2a\u5fc5\u9700\u53c2\u6570\u3002\u5b83\u662f\u8981\u641c\u7d22\u7684\u5b50\u5b57\u7b26\u4e32\u3002<\/span> <\/code>\n <\/div>\n <\/code>\n <\/div>\n <\/code>\n <\/div>\n count: \u8fd9\u662f\u4e00\u4e2a\u5fc5\u9700\u53c2\u6570\uff0c\u663e\u793a\u91cd\u590d\u7ed9\u5b9a\u5b57\u7b26\u4e32\u7684\u6b21\u6570\u3002\u8fd9\u4e2a\u53c2\u6570\u7684\u8303\u56f4\u662f\u4ece0\u5230\u65e0\u7a77\u5927\u3002<\/span> <\/p>\n <\/code>\n <\/div>\n <\/code>\n <\/div>\n <\/body>
\n \u901a\u8fc7\u4f7f\u7528\u5b57\u7b26\u4e32\u5bf9\u8c61(\u4f7f\u7528 new \u5173\u952e\u5b57)<\/span> <\/p>\n\u901a\u8fc7\u4f7f\u7528\u5b57\u7b26\u4e32\u6587\u5b57<\/h2>\n
var <\/span>stringname = \"string value\"<\/span>;<\/pre>\n
\u901a\u8fc7\u4f7f\u7528 String \u5bf9\u8c61(\u4f7f\u7528 new \u5173\u952e\u5b57)<\/h2>\n
var <\/span>stringname = new <\/span>String (\"string literal\"<\/span>);<\/pre>\n
\u5b57\u7b26\u4e32\u5c5e\u6027<\/h2>\n
\n\n
\n \u5c5e\u6027<\/td>\n \u8bf4\u660e<\/td>\n<\/tr>\n \n constructor<\/td>\n \u8fd4\u56de\u5bf9\u8c61\u7684\u6784\u9020\u51fd\u6570\u3002<\/td>\n<\/tr>\n \n length<\/td>\n \u5b83\u8fd4\u56de\u5b57\u7b26\u4e32\u7684\u957f\u5ea6\u3002<\/td>\n<\/tr>\n \n prototype<\/td>\n \u5b83\u5141\u8bb8\u6211\u4eec\u5c06\u65b9\u6cd5\u548c\u5c5e\u6027\u6dfb\u52a0\u5230\u73b0\u6709\u5bf9\u8c61\u4e2d\u3002<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n JavaScript \u5b57\u7b26\u4e32\u6784\u9020\u51fd\u6570\u5c5e\u6027<\/h3>\n
string.constructor<\/pre>\n
var <\/span>str = new <\/span>String(\"Hello World\"<\/span>);\nconsole.log<\/span>(\"Value of str.constructor is: \"<\/span>+str.constructor);<\/pre>\n
Value of str.constructor is: function String<\/span>() { [native <\/span>code] }<\/pre>\n
JavaScript \u5b57\u7b26\u4e32\u957f\u5ea6\u5c5e\u6027<\/h3>\n
string.length<\/pre>\n
var <\/span>str = new <\/span>String(\"Hello World\"<\/span>);\nconsole.log<\/span>(\"The number of characters in the string str is: \"<\/span>+str.length);<\/pre>\n
The number of characters in the string str is: 11<\/pre>\n
JavaScript \u5b57\u7b26\u4e32\u539f\u578b\u5c5e\u6027<\/h3>\n
object.prototype.name = value;<\/pre>\n
function student(name, qualification){\nthis<\/span>.name = name;\nthis<\/span>.qualification = qualification;\n}\nstudent.prototype.age = 20;\nvar <\/span>stu = new <\/span>student('Daniel Grint'<\/span> , 'BCA'<\/span>);\nconsole.log<\/span>(stu.name);\nconsole.log<\/span>(stu.qualification);\nconsole.log<\/span>(stu.age);<\/pre>\n
Daniel Grint\nBCA\n20<\/pre>\n
ES6 \u5b57\u7b26\u4e32\u65b9\u6cd5<\/h2>\n
\n\n
\n \u65b9\u6cd5<\/td>\n \u8bf4\u660e<\/td>\n JavaScript \u7248\u672c<\/td>\n<\/tr>\n \n startsWith<\/td>\n \u5224\u65ad\u4e00\u4e2a\u5b57\u7b26\u4e32\u662f\u5426\u4ee5\u6307\u5b9a\u5b57\u7b26\u4e32\u7684\u5b57\u7b26\u5f00\u5934\u3002<\/td>\n ECMAScript 6<\/td>\n<\/tr>\n \n endsWith<\/td>\n \u5224\u65ad\u4e00\u4e2a\u5b57\u7b26\u4e32\u662f\u5426\u4ee5\u6307\u5b9a\u5b57\u7b26\u4e32\u7684\u5b57\u7b26\u7ed3\u5c3e\u3002<\/td>\n ECMAScript 6<\/td>\n<\/tr>\n \n includes<\/td>\n \u5982\u679c\u6307\u5b9a\u7684\u53c2\u6570\u5728\u5b57\u7b26\u4e32\u4e2d\uff0c\u5219\u8fd4\u56de\u771f\u3002<\/td>\n ECMAScript 6<\/td>\n<\/tr>\n \n repeat<\/td>\n \u5b83\u8fd4\u56de\u4e00\u4e2a\u57fa\u4e8e\u6307\u5b9a\u8ba1\u6570\u53c2\u6570\u91cd\u590d\u7684\u65b0\u5b57\u7b26\u4e32\u3002<\/td>\n ECMAScript 6<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n startsWith() \u65b9\u6cd5<\/h3>\n
string.startsWith<\/span>(searchValue, startPosition)<\/pre>\n
\n startPosition: \u8fd9\u662f\u4e00\u4e2a\u53ef\u9009\u53c2\u6570\u3002\u5176\u9ed8\u8ba4\u503c\u4e3a0\u3002\u5b83\u6307\u5b9a\u5b57\u7b26\u4e32\u4e2d\u5f00\u59cb\u641c\u7d22\u7684\u4f4d\u7f6e\u3002<\/span> <\/p>\nvar <\/span>str = 'Welcome to lidihuo :)'<\/span>; \nconsole.log<\/span>(str.startsWith<\/span>('Wel'<\/span>,0));\nconsole.log<\/span>(str.startsWith<\/span>('wel'<\/span>,0));<\/pre>\n
true<\/span><\/span>\nfalse<\/pre>\n
endsWith() \u65b9\u6cd5<\/h3>\n
string.endsWith<\/span>(searchvalue, length)<\/pre>\n
\n \u957f\u5ea6: \u8fd9\u662f\u4e00\u4e2a\u53ef\u9009\u53c2\u6570\u3002\u5b83\u662f\u5c06\u88ab\u641c\u7d22\u7684\u5b57\u7b26\u4e32\u7684\u957f\u5ea6\u3002\u5982\u679c\u7701\u7565\u6b64\u53c2\u6570\uff0c\u5219\u8be5\u65b9\u6cd5\u5c06\u641c\u7d22\u5b57\u7b26\u4e32\u7684\u5168\u957f\u3002<\/span> <\/p>\nvar <\/span>str = \"Welcome to lidihuo.\"<\/span>;\nconsole.log<\/span>(str.endsWith<\/span>(\"to\"<\/span>, 10))\nconsole.log<\/span>(str.endsWith<\/span>(\"To\"<\/span>, 10))<\/pre>\n
true<\/span><\/span>\nfalse<\/pre>\n
includes() \u65b9\u6cd5<\/h3>\n
string.includes<\/span>(searchValue, start)<\/pre>\n
\n start: \u8868\u793a\u5728\u5b57\u7b26\u4e32\u4e2d\u5f00\u59cb\u641c\u7d22\u7684\u4f4d\u7f6e\u3002\u5176\u9ed8\u8ba4\u503c\u4e3a 0\u3002<\/span> <\/p>\nlet str = \"hello world\"<\/span>\nconsole.log<\/span>(str.includes<\/span>('world'<\/span>,5));\nconsole.log<\/span>(str.includes<\/span>('World'<\/span>, 11))<\/pre>\n
true<\/span><\/span>\nfalse<\/pre>\n
repeat() \u65b9\u6cd5<\/h3>\n
string.repeat<\/span>(count)<\/pre>\n
var <\/span>str = \"hello world\"<\/span>;\nconsole.log<\/span>(str.repeat<\/span>(5));<\/pre>\n
hello worldhello worldhello worldhello worldhello world<\/pre>\n
JavaScript \u5b57\u7b26\u4e32\u65b9\u6cd5<\/h2>\n
\n\n
\n \u65b9\u6cd5<\/td>\n \u8bf4\u660e<\/td>\n JavaScript \u7248\u672c<\/td>\n<\/tr>\n \n charAt()<\/td>\n \u5b83\u63d0\u4f9b\u5b58\u5728\u4e8e\u6307\u5b9a\u7d22\u5f15\u5904\u7684\u5b57\u7b26\u503c\u3002<\/td>\n ECMAScript1<\/td>\n<\/tr>\n \n charCodeAt()<\/td>\n \u5b83\u63d0\u4f9b\u4e86 Unicode \u5b57\u7b26\u503c\uff0c\u8be5\u503c\u51fa\u73b0\u5728\u6307\u5b9a\u7684\u7d22\u5f15\u5904\u3002<\/td>\n ECMAScript1<\/td>\n<\/tr>\n \n concat()<\/td>\n \u5b83\u63d0\u4f9b\u4e86\u4e24\u4e2a\u6216\u591a\u4e2a\u5b57\u7b26\u4e32\u7684\u7ec4\u5408\u3002<\/td>\n ECMAScript1<\/td>\n<\/tr>\n \n match()<\/td>\n \u7528\u4e8e\u5728\u7ed9\u5b9a\u5b57\u7b26\u4e32\u4e2d\u641c\u7d22\u6307\u5b9a\u7684\u6b63\u5219\u8868\u8fbe\u5f0f\uff0c\u5982\u679c\u5339\u914d\u5219\u8fd4\u56de\u8be5\u8868\u8fbe\u5f0f\u3002<\/td>\n ECMAScript1<\/td>\n<\/tr>\n \n toString()<\/td>\n \u5b83\u7ed9\u51fa\u4e00\u4e2a\u4ee3\u8868\u7279\u5b9a\u5bf9\u8c61\u7684\u5b57\u7b26\u4e32\u3002<\/td>\n ECMAScript1<\/td>\n<\/tr>\n \n indexOf()<\/td>\n \u5b83\u7ed9\u51fa\u4e86\u5728\u7ed9\u5b9a\u5b57\u7b26\u4e32\u4e2d\u51fa\u73b0\u7684\u5b57\u7b26\u503c\u7684\u4f4d\u7f6e\u3002<\/td>\n ECMAScript1<\/td>\n<\/tr>\n \n lastIndexOf()<\/td>\n \u5b83\u901a\u8fc7\u4ece\u6700\u540e\u4e00\u4e2a\u4f4d\u7f6e\u641c\u7d22\u4e00\u4e2a\u5b57\u7b26\u6765\u7ed9\u51fa\u7ed9\u5b9a\u5b57\u7b26\u4e32\u4e2d\u7684\u5b57\u7b26\u503c\u4f4d\u7f6e\u3002<\/td>\n \u6b27\u5171\u4f53MAScript1<\/td>\n<\/tr>\n \n replace()<\/td>\n \u5b83\u7528\u6307\u5b9a\u7684\u66ff\u6362\u66ff\u6362\u7ed9\u5b9a\u7684\u5b57\u7b26\u4e32\u3002<\/td>\n ECMAScript1<\/td>\n<\/tr>\n \n search()<\/td>\n \u5b83\u641c\u7d22\u7279\u5b9a\u7684\u6b63\u5219\u8868\u8fbe\u5f0f\u5e76\u5728\u5339\u914d\u53d1\u751f\u65f6\u8fd4\u56de\u5176\u4f4d\u7f6e\u3002<\/td>\n ECMAScript1<\/td>\n<\/tr>\n \n valueOf()<\/td>\n \u5b83\u63d0\u4f9b\u5b57\u7b26\u4e32\u5bf9\u8c61\u7684\u539f\u59cb\u503c\u3002<\/td>\n ECMAScript1<\/td>\n<\/tr>\n \n slice()<\/td>\n \u7528\u4e8e\u83b7\u53d6\u7ed9\u5b9a\u5b57\u7b26\u4e32\u7684\u4e00\u90e8\u5206\u3002<\/td>\n ECMAScript1<\/td>\n<\/tr>\n \n split()<\/td>\n \u5c06\u5b57\u7b26\u4e32\u62c6\u5206\u4e3a\u5b50\u5b57\u7b26\u4e32\u6570\u7ec4\u5e76\u8fd4\u56de\u65b0\u521b\u5efa\u7684\u6570\u7ec4\u3002<\/td>\n ECMAScript1<\/td>\n<\/tr>\n \n substr()<\/td>\n \u5b83\u6839\u636e\u6307\u5b9a\u7684\u957f\u5ea6\u548c\u8d77\u59cb\u4f4d\u7f6e\u83b7\u53d6\u7ed9\u5b9a\u5b57\u7b26\u4e32\u7684\u90e8\u5206\u3002<\/td>\n ECMAScript1<\/td>\n<\/tr>\n \n substring()<\/td>\n \u5b83\u6839\u636e\u6307\u5b9a\u7684\u7d22\u5f15\u83b7\u53d6\u7ed9\u5b9a\u5b57\u7b26\u4e32\u7684\u4e00\u90e8\u5206\u3002<\/td>\n ECMAScript1<\/td>\n<\/tr>\n \n toLocaleLowerCase()<\/td>\n \u5b83\u6839\u636e\u4e3b\u673a\u7684\u5f53\u524d\u6bd4\u4f8b\u5c06\u7ed9\u5b9a\u7684\u5b57\u7b26\u4e32\u8f6c\u6362\u4e3a\u5c0f\u5199\u5b57\u6bcd\u3002<\/td>\n ECMAScript1<\/td>\n<\/tr>\n \n toLocaleUpperCase()<\/td>\n \u5b83\u6839\u636e\u4e3b\u673a\u5f53\u524d\u7684\u6bd4\u4f8b\u5c06\u7ed9\u5b9a\u7684\u5b57\u7b26\u4e32\u8f6c\u6362\u4e3a\u5927\u5199\u5b57\u6bcd\u3002<\/td>\n ECMAScript1<\/td>\n<\/tr>\n \n toLowerCase()<\/td>\n \u5b83\u53ea\u662f\u5c06\u7ed9\u5b9a\u7684\u5b57\u7b26\u4e32\u8f6c\u6362\u4e3a\u5c0f\u5199\u5b57\u6bcd\u3002<\/td>\n ECMAScript1<\/td>\n<\/tr>\n \n toUpperCase()<\/td>\n \u5b83\u53ea\u662f\u5c06\u7ed9\u5b9a\u7684\u5b57\u7b26\u4e32\u8f6c\u6362\u4e3a\u5c0f\u5199\u5b57\u6bcd\u3002<\/td>\n ECMAScript1<\/td>\n<\/tr>\n \n trim()<\/td>\n \u5b83\u4ece\u5b57\u7b26\u4e32\u7684\u5de6\u4fa7\u548c\u53f3\u4fa7\u4fee\u526a\u7a7a\u767d\u3002<\/td>\n ECMAScript5<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n
\n<\/html><\/p>\n","protected":false},"excerpt":{"rendered":"ES6 \u5b57\u7b26\u4e32zh-cn","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[161],"tags":[],"class_list":["post-1924","post","type-post","status-publish","format-standard","hentry","category-es6jc"],"_links":{"self":[{"href":"https:\/\/bianchenghao6.com\/wp-json\/wp\/v2\/posts\/1924"}],"collection":[{"href":"https:\/\/bianchenghao6.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/bianchenghao6.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/bianchenghao6.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/bianchenghao6.com\/wp-json\/wp\/v2\/comments?post=1924"}],"version-history":[{"count":0,"href":"https:\/\/bianchenghao6.com\/wp-json\/wp\/v2\/posts\/1924\/revisions"}],"wp:attachment":[{"href":"https:\/\/bianchenghao6.com\/wp-json\/wp\/v2\/media?parent=1924"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/bianchenghao6.com\/wp-json\/wp\/v2\/categories?post=1924"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/bianchenghao6.com\/wp-json\/wp\/v2\/tags?post=1924"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}