{"id":32347,"date":"2024-11-25T15:08:51","date_gmt":"2024-11-25T07:08:51","guid":{"rendered":"https:\/\/fwq.ai\/blog\/32347\/"},"modified":"2024-11-25T15:08:51","modified_gmt":"2024-11-25T07:08:51","slug":"%e4%bd%bf%e7%94%a8%e5%9f%ba%e6%9c%ac%e5%ad%97%e7%ac%a6%e4%b8%b2%e3%80%81%e6%95%b0%e5%ad%97%e5%92%8c%e5%b8%83%e5%b0%94%e5%80%bc","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/32347\/","title":{"rendered":"\u4f7f\u7528\u57fa\u672c\u5b57\u7b26\u4e32\u3001\u6570\u5b57\u548c\u5e03\u5c14\u503c"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/000\/000\/164\/169330470343616.jpg\" class=\"aligncenter\" title=\"\u4f7f\u7528\u57fa\u672c\u5b57\u7b26\u4e32\u3001\u6570\u5b57\u548c\u5e03\u5c14\u503c\u63d2\u56fe\" alt=\"\u4f7f\u7528\u57fa\u672c\u5b57\u7b26\u4e32\u3001\u6570\u5b57\u548c\u5e03\u5c14\u503c\u63d2\u56fe\" \/><\/p>\n<p>\u4e0d\u8981\u5bf9\u5b57\u7b26\u4e32\u3001\u6570\u5b57\u548c\u5e03\u5c14\u6587\u5b57\u53ef\u4ee5\u88ab\u89c6\u4e3a\u5177\u6709\u5c5e\u6027\u7684\u5bf9\u8c61\u8fd9\u4e00\u4e8b\u5b9e\u611f\u5230\u56f0\u60d1\uff08\u4f8b\u5982\uff0ctrue.toString()\uff09\u3002\u5f53\u8fd9\u4e9b\u57fa\u5143\u503c\u901a\u8fc7\u5c1d\u8bd5\u8bbf\u95ee\u5176\u5c5e\u6027\u800c\u88ab\u89c6\u4e3a\u5bf9\u8c61\u65f6\uff0cJavaScript \u5c06\u4ece\u57fa\u5143\u7684\u5173\u8054\u6784\u9020\u51fd\u6570\u521b\u5efa\u4e00\u4e2a\u5305\u88c5\u5668\u5bf9\u8c61\uff0c\u4ee5\u4fbf\u53ef\u4ee5\u8bbf\u95ee\u5305\u88c5\u5668\u5bf9\u8c61\u7684\u5c5e\u6027\u548c\u65b9\u6cd5\u3002<\/p>\n<\/p>\n<p>\u4e00\u65e6\u8bbf\u95ee\u4e86\u5c5e\u6027\uff0c\u5305\u88c5\u5668\u5bf9\u8c61\u5c31\u4f1a\u88ab\u4e22\u5f03\u3002\u8fd9\u79cd\u8f6c\u6362\u5141\u8bb8\u6211\u4eec\u7f16\u5199\u4ee3\u7801\uff0c\u4f7f\u5176\u770b\u8d77\u6765\u597d\u50cf\u539f\u59cb\u503c\u5b9e\u9645\u4e0a\u662f\u4e00\u4e2a\u5bf9\u8c61\u3002\u8bf4\u5b9e\u8bdd\uff0c\u5f53\u5b83\u5728\u4ee3\u7801\u4e2d\u88ab\u89c6\u4e3a\u5bf9\u8c61\u65f6\uff0cJavaScript \u4f1a\u5c06\u5176\u8f6c\u6362\u4e3a\u5bf9\u8c61\uff0c\u4ee5\u4fbf\u5c5e\u6027\u8bbf\u95ee\u53ef\u4ee5\u5de5\u4f5c\uff0c\u7136\u540e\u5728\u8fd4\u56de\u503c\u540e\u5c06\u5176\u8f6c\u6362\u56de\u539f\u59cb\u503c\u3002\u8fd9\u91cc\u9700\u8981\u6ce8\u610f\u7684\u5173\u952e\u662f\u6b63\u5728\u53d1\u751f\u7684\u4e8b\u60c5\uff0c\u800c JavaScript \u6b63\u5728\u5e55\u540e\u4e3a\u60a8\u505a\u8fd9\u4ef6\u4e8b\u3002<\/p>\n<hr>\n<h2>\u539f\u59cb\u503c\u6837\u672c<\/h2>\n<p>\u8fd9\u91cc\u6709\u4e00\u4e9b\u793a\u4f8b\u6765\u6f14\u793a\u6211\u6b63\u5728\u8c08\u8bba\u7684\u5185\u5bb9\uff1a<\/p>\n<p>\u5b57\u7b26\u4e32\u793a\u4f8b\uff1asample56.html<\/p>\n<pre>\n&lt;script&gt;\n\n\t\/\/ String object treated like an object.\n\tvar stringObject = new String('foo');\n\tconsole.log(stringObject.length); \/\/ Logs 3.\n\tconsole.log(stringObject['length']); \/\/ Logs 3.\n\n\t\/\/ String literal\/primitive converted to an object when treated as an object.\n\tvar stringLiteral = 'foo';\n\tconsole.log(stringLiteral.length); \/\/ Logs 3.\n\tconsole.log(stringLiteral['length']); \/\/ Logs 3.\n\tconsole.log('bar'.length); \/\/ Logs 3.\n\tconsole.log('bar'['length']); \/\/ Logs 3.\n\n&lt;\/script&gt;<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p>\u6570\u5b57\u793a\u4f8b\uff1asample57.html<\/p>\n<pre>\n&lt;script&gt;\n\n\t\/\/ Number object treated like an object.\n\tvar numberObject = new Number(1.10023);\n\tconsole.log(numberObject.toFixed()); \/\/ Logs 1.\n\tconsole.log(numberObject['toFixed']()); \/\/ Logs 1.\n\n\t\/\/ Number literal\/primitive converted to an object when treated as an object.\n\tvar numberLiteral = 1.10023;\n\tconsole.log(numberLiteral.toFixed()); \/\/ Logs 1.\n\tconsole.log(numberLiteral['toFixed']()); \/\/ Logs 1.\n\tconsole.log((1234).toString()); \/\/ Logs '1234'.\n\tconsole.log(1234['toString']()); \/\/ Logs '1234'.\n\n&lt;\/script&gt;<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p>\u5e03\u5c14\u793a\u4f8b\uff1asample58.html<\/p>\n<pre>\n&lt;script&gt;\n\n\t\/\/ Boolean object treated like an object.\n\tvar booleanObject = new Boolean(0);\n\tconsole.log(booleanObject.toString()); \/\/ Logs 'false'.\n\tconsole.log(booleanObject['toString']()); \/\/ Logs 'false'.\n\n\t\/\/ Boolean literal\/primitive converted to an object when treated as an object.\n\tvar booleanLiteral = false;\n\tconsole.log(booleanLiteral.toString()); \/\/ Logs 'false'.\n\tconsole.log(booleanLiteral['toString']()); \/\/ Logs 'false'.\n\tconsole.log((true).toString()); \/\/ Logs 'true'.\n\tconsole.log(true['toString']()); \/\/ Logs 'true'.\n\n&lt;\/script&gt;<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p>\u76f4\u63a5\u8bbf\u95ee\u539f\u59cb\u6570\u5b57\u7684\u5c5e\u6027\uff08\u4e0d\u5b58\u50a8\u5728\u53d8\u91cf\u4e2d\uff09\u65f6\uff0c\u5fc5\u987b\u5148\u8ba1\u7b97\u8be5\u6570\u5b57\uff0c\u7136\u540e\u624d\u80fd\u5c06\u8be5\u503c\u89c6\u4e3a\u5bf9\u8c61\uff08\u4f8b\u5982\uff0c (1).toString(); \u62161..toString();)\u3002\u4e3a\u4ec0\u4e48\u662f\u4e24\u4e2a\u70b9\uff1f\u7b2c\u4e00\u4e2a\u70b9\u88ab\u89c6\u4e3a\u6570\u5b57\u5c0f\u6570\uff0c\u800c\u4e0d\u662f\u7528\u4e8e\u8bbf\u95ee\u5bf9\u8c61\u5c5e\u6027\u7684\u8fd0\u7b97\u7b26\u3002<\/p>\n<hr>\n<h2>\u60a8\u901a\u5e38\u5e94\u8be5\u4f7f\u7528\u539f\u59cb\u5b57\u7b26\u4e32\u3001\u6570\u5b57\u548c\u5e03\u5c14\u503c<\/h2>\n<p>\u8868\u793a\u5b57\u7b26\u4e32\u3001\u6570\u5b57\u6216\u5e03\u5c14\u503c\u7684\u6587\u5b57\/\u539f\u59cb\u503c\u7684\u4e66\u5199\u901f\u5ea6\u66f4\u5feb\uff0c\u5e76\u4e14\u6587\u5b57\u5f62\u5f0f\u66f4\u7b80\u6d01\u3002<\/p>\n<p>\u56e0\u6b64\uff0c\u60a8\u5e94\u8be5\u4f7f\u7528\u6587\u5b57\u503c\u3002\u6b64\u5916\uff0c typeof \u8fd0\u7b97\u7b26\u7684\u51c6\u786e\u6027\u53d6\u51b3\u4e8e\u60a8\u521b\u5efa\u503c\u7684\u65b9\u5f0f\uff08\u6587\u5b57\u4e0e\u6784\u9020\u51fd\u6570\u8c03\u7528\uff09\u3002\u5982\u679c\u60a8\u521b\u5efa\u5b57\u7b26\u4e32\u3001\u6570\u5b57\u6216\u5e03\u5c14\u5bf9\u8c61\uff0c\u5219 typeof \u8fd0\u7b97\u7b26\u4f1a\u5c06\u7c7b\u578b\u62a5\u544a\u4e3a\u5bf9\u8c61\u3002\u5982\u679c\u60a8\u4f7f\u7528\u6587\u5b57\uff0c\u5219 typeof \u8fd0\u7b97\u7b26\u5c06\u8fd4\u56de\u5b9e\u9645\u503c\u7c7b\u578b\u7684\u5b57\u7b26\u4e32\u540d\u79f0\uff08\u4f8b\u5982\uff0ctypeof &#8216;foo&#8217; \/\/ returns &#8216;string&#8217;\uff09\u3002<\/p>\n<p>\u6211\u5728\u4e0b\u9762\u7684\u4ee3\u7801\u4e2d\u6f14\u793a\u4e86\u8fd9\u4e00\u4e8b\u5b9e\u3002<\/p>\n<p>\u793a\u4f8b\uff1asample59.html<\/p>\n<pre>\n&lt;script&gt;\n\n\t\/\/ String, number, and Boolean objects.\n\tconsole.log(typeof new String('foo')); \/\/ Logs 'object'.\n\tconsole.log(typeof new Number(1)); \/\/ Logs 'object'.\n\tconsole.log(typeof new Boolean(true)); \/\/ Logs 'object'.\n\n\t\/\/ String, number, and Boolean literals\/primitives.\n\tconsole.log(typeof 'foo'); \/\/ Logs 'string'.\n\tconsole.log(typeof 1); \/\/ Logs 'number'.\n\tconsole.log(typeof true); \/\/ Logs 'boolean'.\n\n&lt;\/script&gt;<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<hr>\n<h2>\u7ed3\u8bba<\/h2>\n<p>\u5982\u679c\u60a8\u7684\u7a0b\u5e8f\u4f9d\u8d56 typeof \u8fd0\u7b97\u7b26\u6765\u6839\u636e\u8fd9\u4e9b\u57fa\u672c\u7c7b\u578b\u8bc6\u522b\u5b57\u7b26\u4e32\u3001\u6570\u5b57\u6216\u5e03\u5c14\u503c\uff0c\u5219\u5e94\u907f\u514d\u4f7f\u7528 String\u3001Number \u548c Boolean \u6784\u9020\u51fd\u6570\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u4f7f\u7528\u57fa\u672c\u5b57\u7b26\u4e32\u3001\u6570\u5b57\u548c\u5e03\u5c14\u503c\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4e0d\u8981\u5bf9\u5b57\u7b26\u4e32\u3001\u6570\u5b57\u548c\u5e03\u5c14\u6587\u5b57\u53ef\u4ee5\u88ab\u89c6\u4e3a\u5177\u6709\u5c5e\u6027\u7684\u5bf9\u8c61\u8fd9\u4e00\u4e8b\u5b9e\u611f\u5230\u56f0\u60d1\uff08\u4f8b\u5982\uff0ctrue.toString()\uff09\u3002\u5f53\u8fd9\u4e9b\u57fa\u5143\u503c\u901a\u8fc7\u5c1d\u8bd5\u8bbf\u95ee\u5176\u5c5e\u6027\u800c\u88ab\u89c6\u4e3a\u5bf9\u8c61\u65f6\uff0cJavaScript \u5c06\u4ece\u57fa\u5143\u7684\u5173\u8054\u6784\u9020\u51fd\u6570\u521b\u5efa\u4e00\u4e2a\u5305\u88c5\u5668\u5bf9\u8c61\uff0c\u4ee5\u4fbf\u53ef\u4ee5\u8bbf\u95ee\u5305\u88c5\u5668\u5bf9\u8c61\u7684\u5c5e\u6027\u548c\u65b9\u6cd5\u3002 \u4e00\u65e6\u8bbf\u95ee\u4e86\u5c5e\u6027\uff0c\u5305\u88c5\u5668\u5bf9\u8c61\u5c31\u4f1a\u88ab\u4e22\u5f03\u3002\u8fd9\u79cd\u8f6c\u6362\u5141\u8bb8\u6211\u4eec\u7f16\u5199\u4ee3\u7801\uff0c\u4f7f\u5176\u770b\u8d77\u6765\u597d\u50cf\u539f\u59cb\u503c\u5b9e\u9645\u4e0a\u662f\u4e00\u4e2a\u5bf9\u8c61\u3002\u8bf4\u5b9e\u8bdd\uff0c\u5f53\u5b83\u5728\u4ee3\u7801\u4e2d\u88ab\u89c6\u4e3a\u5bf9\u8c61\u65f6\uff0cJavaScript \u4f1a\u5c06\u5176\u8f6c\u6362\u4e3a\u5bf9\u8c61\uff0c\u4ee5\u4fbf\u5c5e\u6027\u8bbf\u95ee\u53ef\u4ee5\u5de5\u4f5c\uff0c\u7136\u540e\u5728\u8fd4\u56de\u503c\u540e\u5c06\u5176\u8f6c\u6362\u56de\u539f\u59cb\u503c\u3002\u8fd9\u91cc\u9700\u8981\u6ce8\u610f\u7684\u5173\u952e\u662f\u6b63\u5728\u53d1\u751f\u7684\u4e8b\u60c5\uff0c\u800c JavaScript \u6b63\u5728\u5e55\u540e\u4e3a\u60a8\u505a\u8fd9\u4ef6\u4e8b\u3002 \u539f\u59cb\u503c\u6837\u672c \u8fd9\u91cc\u6709\u4e00\u4e9b\u793a\u4f8b\u6765\u6f14\u793a\u6211\u6b63\u5728\u8c08\u8bba\u7684\u5185\u5bb9\uff1a \u5b57\u7b26\u4e32\u793a\u4f8b\uff1asample56.html &lt;script&gt; \/\/ String object treated like an object. var stringObject = new String(&#8216;foo&#8217;); console.log(stringObject.length); \/\/ Logs 3. console.log(stringObject[&#8216;length&#8217;]); \/\/ Logs 3. \/\/ String literal\/primitive converted to an object when treated as an object. var stringLiteral = &#8216;foo&#8217;; console.log(stringLiteral.length); \/\/ Logs 3. console.log(stringLiteral[&#8216;length&#8217;]); \/\/ Logs 3. console.log(&#8216;bar&#8217;.length); [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[18],"tags":[],"class_list":["post-32347","post","type-post","status-publish","format-standard","hentry","category-cms"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/32347","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=32347"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/32347\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=32347"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=32347"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=32347"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}