{"id":3137,"date":"2024-11-10T13:17:19","date_gmt":"2024-11-10T05:17:19","guid":{"rendered":"https:\/\/fwq.ai\/blog\/3137\/"},"modified":"2024-11-10T13:17:19","modified_gmt":"2024-11-10T05:17:19","slug":"js%e5%a6%82%e4%bd%95%e8%bf%90%e8%a1%8c","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/3137\/","title":{"rendered":".js\u5982\u4f55\u8fd0\u884c"},"content":{"rendered":"<blockquote><p>\n  javascript \u4f5c\u4e3a\u4e00\u79cd\u89e3\u91ca\u578b\u8bed\u8a00\uff0c\u5176\u8fd0\u884c\u65b9\u5f0f\u5982\u4e0b\uff1a\u89e3\u91ca\u5f15\u64ce\u89e3\u6790\u4ee3\u7801\u6210\u62bd\u8c61\u8bed\u6cd5\u6811\uff08ast\uff09\u3002\u521b\u5efa\u6267\u884c\u4e0a\u4e0b\u6587\uff0c\u5305\u542b\u53d8\u91cf\u3001\u51fd\u6570\u548c\u4f5c\u7528\u57df\u4fe1\u606f\u3002\u4ece ast \u6839\u8282\u70b9\u6267\u884c\u4ee3\u7801\uff0c\u9010\u4e2a\u89e3\u6790\u8282\u70b9\u6267\u884c\u76f8\u5e94\u64cd\u4f5c\u3002\u8ddf\u8e2a\u503c\u53d8\u5316\uff0c\u66f4\u65b0\u53d8\u91cf\u6216\u4f5c\u7528\u57df\u4e2d\u7684\u503c\u3002\u5f02\u5e38\u5904\u7406\u7a0b\u5e8f\u5904\u7406\u9519\u8bef\uff0c\u6062\u590d\u6267\u884c\u6216\u63d0\u4f9b\u9519\u8bef\u62a5\u544a\u3002\u4e8b\u4ef6\u5faa\u73af\u7ba1\u7406\u5f02\u6b65\u64cd\u4f5c\uff0c\u5c06\u5176\u6dfb\u52a0\u5230\u4e8b\u4ef6\u961f\u5217\u4e2d\u5b89\u6392\u7a0d\u540e\u5904\u7406\u3002\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202411\/08\/2024110804430453257.jpg\" class=\"aligncenter\" title=\".js\u5982\u4f55\u8fd0\u884c\u63d2\u56fe\" alt=\".js\u5982\u4f55\u8fd0\u884c\u63d2\u56fe\" \/><\/p>\n<p><strong>JavaScript \u5982\u4f55\u8fd0\u884c<\/strong><\/p>\n<p>JavaScript \u4f5c\u4e3a\u4e00\u79cd\u89e3\u91ca\u578b\u8bed\u8a00\uff0c\u5176\u8fd0\u884c\u65b9\u5f0f\u4e0e\u7f16\u8bd1\u578b\u8bed\u8a00\u6709\u7740\u672c\u8d28\u3002\u4ee5\u4e0b\u662f JavaScript \u7684\u8fd0\u884c\u6d41\u7a0b\uff1a<\/p>\n<p><strong>1. \u89e3\u91ca\u5f15\u64ce<\/strong><\/p>\n<p>JavaScript \u5f15\u64ce\uff0c\u4f8b\u5982 Chrome \u7684 V8 \u5f15\u64ce\u6216 Mozilla \u7684 SpiderMonkey \u5f15\u64ce\uff0c\u8d1f\u8d23\u89e3\u91ca\u548c\u6267\u884c JavaScript \u4ee3\u7801\u3002<\/p>\n<p><strong>2. \u4ee3\u7801\u89e3\u6790<\/strong><\/p>\n<p>\u89e3\u91ca\u5f15\u64ce\u9996\u5148\u5c06 JavaScript \u4ee3\u7801\u89e3\u6790\u6210\u4e00\u68f5\u62bd\u8c61\u8bed\u6cd5\u6811 (AST)\u3002AST \u662f\u4ee3\u7801\u7ed3\u6784\u7684\u6811\u5f62\u8868\u793a\uff0c\u5b83\u4fdd\u7559\u4e86\u4ee3\u7801\u4e2d\u53d8\u91cf\u3001\u51fd\u6570\u548c\u8868\u8fbe\u5f0f\u4e4b\u95f4\u7684\u5173\u7cfb\u3002<\/p>\n<p><strong>3. \u6267\u884c\u4e0a\u4e0b\u6587\u7684\u521b\u5efa<\/strong><\/p>\n<p>\u5728\u89e3\u91ca\u8fc7\u7a0b\u4e2d\uff0c\u5f15\u64ce\u5c06\u6839\u636e\u4ee3\u7801\u4f4d\u7f6e\u521b\u5efa\u4e0d\u540c\u7684\u6267\u884c\u4e0a\u4e0b\u6587\u3002\u6267\u884c\u4e0a\u4e0b\u6587\u5305\u542b\u7279\u5b9a\u4f4d\u7f6e\u7684\u53d8\u91cf\u3001\u51fd\u6570\u548c\u4fe1\u606f\u3002<\/p>\n<p><strong>4. \u4ee3\u7801\u6267\u884c<\/strong><\/p>\n<p>\u5f15\u64ce\u4ece AST \u7684\u6839\u8282\u70b9\u5f00\u59cb\u6267\u884c\u4ee3\u7801\u3002\u5b83\u9010\u6b65\u89e3\u6790\u6bcf\u4e2a\u8282\u70b9\u5e76\u6839\u636e\u8282\u70b9\u7c7b\u578b\uff08\u53d8\u91cf\u58f0\u660e\u3001\u51fd\u6570\u8c03\u7528\u3001\u903b\u8f91\u8868\u8fbe\u5f0f\u7b49\uff09\u6267\u884c\u76f8\u5e94\u7684\u64cd\u4f5c\u3002<\/p>\n<p><strong>5. \u503c\u4f20\u64ad<\/strong><\/p>\n<p>\u89e3\u91ca\u5f15\u64ce\u5728\u6267\u884c\u8fc7\u7a0b\u4e2d\u4e0d\u65ad\u8ddf\u8e2a\u503c\u7684\u53d8\u5316\u3002\u5f53\u4e00\u4e2a\u503c\u88ab\u8d4b\u503c\u6216\u4fee\u6539\u65f6\uff0c\u5b83\u4f1a\u81ea\u52a8\u66f4\u65b0\u5173\u8054\u7684\u53d8\u91cf\u6216\u4f5c\u7528\u57df\u4e2d\u7684\u503c\u3002<\/p>\n<p><strong>6. \u5f02\u5e38\u5904\u7406<\/strong><\/p>\n<p>\u5982\u679c\u5728\u6267\u884c\u8fc7\u7a0b\u4e2d\u9047\u5230\u9519\u8bef\u6216\u5f02\u5e38\uff0c\u5f15\u64ce\u5c06\u4e2d\u6b62\u6267\u884c\u5e76\u89e6\u53d1\u5f02\u5e38\u3002\u5f02\u5e38\u5904\u7406\u7a0b\u5e8f\u53ef\u4ee5\u5904\u7406\u9519\u8bef\u5e76\u6062\u590d\u6267\u884c\u6d41\u7a0b\u6216\u63d0\u4f9b\u9519\u8bef\u62a5\u544a\u3002<\/p>\n<p><strong>7. \u4e8b\u4ef6\u5faa\u73af<\/strong><\/p>\n<p>JavaScript \u5728\u6d4f\u89c8\u5668\u4e2d\u901a\u5e38\u5728\u5355\u7ebf\u7a0b\u73af\u5883\u4e2d\u8fd0\u884c\u3002\u5b83\u4f7f\u7528\u4e00\u4e2a\u4e8b\u4ef6\u5faa\u73af\u6765\u7ba1\u7406\u5f02\u6b65\u64cd\u4f5c\uff0c\u4f8b\u5982\u5b9a\u65f6\u5668\u3001\u7f51\u7edc\u8bf7\u6c42\u548c\u7528\u6237\u8f93\u5165\u3002\u5f53\u4e00\u4e2a\u5f02\u6b65\u4e8b\u4ef6\u53d1\u751f\u65f6\uff0c\u5f15\u64ce\u5c06\u5b83\u6dfb\u52a0\u5230\u4e8b\u4ef6\u961f\u5217\u4e2d\uff0c\u5e76\u5b89\u6392\u7a0d\u540e\u5904\u7406\u5b83\u3002<\/p>\n<p><strong>\u793a\u4f8b\uff1a<\/strong><\/p>\n<p>\u8003\u8651\u4ee5\u4e0b\u4ee3\u7801\uff1a<\/p>\n<pre>let name = \"John\";\nconsole.log(name);<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u5f53\u5f15\u64ce\u89e3\u6790\u548c\u6267\u884c\u8fd9\u6bb5\u4ee3\u7801\u65f6\uff0c\u4f1a\u53d1\u751f\u4ee5\u4e0b\u6b65\u9aa4\uff1a<\/p>\n<ul>\n<li>\u521b\u5efa\u6267\u884c\u4e0a\u4e0b\u6587\uff0c\u5c06 name \u53d8\u91cf\u7ed1\u5b9a\u5230\u503c &#8220;John&#8221;\u3002<\/li>\n<li>\u89e3\u6790 console.log() \u8282\u70b9\uff0c\u5e76\u8c03\u7528 console \u5bf9\u8c61\u4e0a\u7684 log() \u65b9\u6cd5\u3002<\/li>\n<li>\u5c06 name \u53d8\u91cf\u7684\u503c\u4f20\u9012\u7ed9 log() \u65b9\u6cd5\u3002<\/li>\n<li>\u5c06 &#8220;John&#8221; \u8f93\u51fa\u5230\u63a7\u5236\u53f0\u3002<\/li>\n<\/ul>\n<p>\u4ee5\u4e0a\u5c31\u662f.js\u5982\u4f55\u8fd0\u884c\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>javascript \u4f5c\u4e3a\u4e00\u79cd\u89e3\u91ca\u578b\u8bed\u8a00\uff0c\u5176\u8fd0\u884c\u65b9\u5f0f\u5982\u4e0b\uff1a\u89e3\u91ca\u5f15\u64ce\u89e3\u6790\u4ee3\u7801\u6210\u62bd\u8c61\u8bed\u6cd5\u6811\uff08ast\uff09\u3002\u521b\u5efa\u6267\u884c\u4e0a\u4e0b\u6587\uff0c\u5305\u542b\u53d8\u91cf\u3001\u51fd\u6570\u548c\u4f5c\u7528\u57df\u4fe1\u606f\u3002\u4ece ast \u6839\u8282\u70b9\u6267\u884c\u4ee3\u7801\uff0c\u9010\u4e2a\u89e3\u6790\u8282\u70b9\u6267\u884c\u76f8\u5e94\u64cd\u4f5c\u3002\u8ddf\u8e2a\u503c\u53d8\u5316\uff0c\u66f4\u65b0\u53d8\u91cf\u6216\u4f5c\u7528\u57df\u4e2d\u7684\u503c\u3002\u5f02\u5e38\u5904\u7406\u7a0b\u5e8f\u5904\u7406\u9519\u8bef\uff0c\u6062\u590d\u6267\u884c\u6216\u63d0\u4f9b\u9519\u8bef\u62a5\u544a\u3002\u4e8b\u4ef6\u5faa\u73af\u7ba1\u7406\u5f02\u6b65\u64cd\u4f5c\uff0c\u5c06\u5176\u6dfb\u52a0\u5230\u4e8b\u4ef6\u961f\u5217\u4e2d\u5b89\u6392\u7a0d\u540e\u5904\u7406\u3002 JavaScript \u5982\u4f55\u8fd0\u884c JavaScript \u4f5c\u4e3a\u4e00\u79cd\u89e3\u91ca\u578b\u8bed\u8a00\uff0c\u5176\u8fd0\u884c\u65b9\u5f0f\u4e0e\u7f16\u8bd1\u578b\u8bed\u8a00\u6709\u7740\u672c\u8d28\u3002\u4ee5\u4e0b\u662f JavaScript \u7684\u8fd0\u884c\u6d41\u7a0b\uff1a 1. \u89e3\u91ca\u5f15\u64ce JavaScript \u5f15\u64ce\uff0c\u4f8b\u5982 Chrome \u7684 V8 \u5f15\u64ce\u6216 Mozilla \u7684 SpiderMonkey \u5f15\u64ce\uff0c\u8d1f\u8d23\u89e3\u91ca\u548c\u6267\u884c JavaScript \u4ee3\u7801\u3002 2. \u4ee3\u7801\u89e3\u6790 \u89e3\u91ca\u5f15\u64ce\u9996\u5148\u5c06 JavaScript \u4ee3\u7801\u89e3\u6790\u6210\u4e00\u68f5\u62bd\u8c61\u8bed\u6cd5\u6811 (AST)\u3002AST \u662f\u4ee3\u7801\u7ed3\u6784\u7684\u6811\u5f62\u8868\u793a\uff0c\u5b83\u4fdd\u7559\u4e86\u4ee3\u7801\u4e2d\u53d8\u91cf\u3001\u51fd\u6570\u548c\u8868\u8fbe\u5f0f\u4e4b\u95f4\u7684\u5173\u7cfb\u3002 3. \u6267\u884c\u4e0a\u4e0b\u6587\u7684\u521b\u5efa \u5728\u89e3\u91ca\u8fc7\u7a0b\u4e2d\uff0c\u5f15\u64ce\u5c06\u6839\u636e\u4ee3\u7801\u4f4d\u7f6e\u521b\u5efa\u4e0d\u540c\u7684\u6267\u884c\u4e0a\u4e0b\u6587\u3002\u6267\u884c\u4e0a\u4e0b\u6587\u5305\u542b\u7279\u5b9a\u4f4d\u7f6e\u7684\u53d8\u91cf\u3001\u51fd\u6570\u548c\u4fe1\u606f\u3002 4. \u4ee3\u7801\u6267\u884c \u5f15\u64ce\u4ece AST \u7684\u6839\u8282\u70b9\u5f00\u59cb\u6267\u884c\u4ee3\u7801\u3002\u5b83\u9010\u6b65\u89e3\u6790\u6bcf\u4e2a\u8282\u70b9\u5e76\u6839\u636e\u8282\u70b9\u7c7b\u578b\uff08\u53d8\u91cf\u58f0\u660e\u3001\u51fd\u6570\u8c03\u7528\u3001\u903b\u8f91\u8868\u8fbe\u5f0f\u7b49\uff09\u6267\u884c\u76f8\u5e94\u7684\u64cd\u4f5c\u3002 5. \u503c\u4f20\u64ad \u89e3\u91ca\u5f15\u64ce\u5728\u6267\u884c\u8fc7\u7a0b\u4e2d\u4e0d\u65ad\u8ddf\u8e2a\u503c\u7684\u53d8\u5316\u3002\u5f53\u4e00\u4e2a\u503c\u88ab\u8d4b\u503c\u6216\u4fee\u6539\u65f6\uff0c\u5b83\u4f1a\u81ea\u52a8\u66f4\u65b0\u5173\u8054\u7684\u53d8\u91cf\u6216\u4f5c\u7528\u57df\u4e2d\u7684\u503c\u3002 6. \u5f02\u5e38\u5904\u7406 \u5982\u679c\u5728\u6267\u884c\u8fc7\u7a0b\u4e2d\u9047\u5230\u9519\u8bef\u6216\u5f02\u5e38\uff0c\u5f15\u64ce\u5c06\u4e2d\u6b62\u6267\u884c\u5e76\u89e6\u53d1\u5f02\u5e38\u3002\u5f02\u5e38\u5904\u7406\u7a0b\u5e8f\u53ef\u4ee5\u5904\u7406\u9519\u8bef\u5e76\u6062\u590d\u6267\u884c\u6d41\u7a0b\u6216\u63d0\u4f9b\u9519\u8bef\u62a5\u544a\u3002 7. \u4e8b\u4ef6\u5faa\u73af JavaScript \u5728\u6d4f\u89c8\u5668\u4e2d\u901a\u5e38\u5728\u5355\u7ebf\u7a0b\u73af\u5883\u4e2d\u8fd0\u884c\u3002\u5b83\u4f7f\u7528\u4e00\u4e2a\u4e8b\u4ef6\u5faa\u73af\u6765\u7ba1\u7406\u5f02\u6b65\u64cd\u4f5c\uff0c\u4f8b\u5982\u5b9a\u65f6\u5668\u3001\u7f51\u7edc\u8bf7\u6c42\u548c\u7528\u6237\u8f93\u5165\u3002\u5f53\u4e00\u4e2a\u5f02\u6b65\u4e8b\u4ef6\u53d1\u751f\u65f6\uff0c\u5f15\u64ce\u5c06\u5b83\u6dfb\u52a0\u5230\u4e8b\u4ef6\u961f\u5217\u4e2d\uff0c\u5e76\u5b89\u6392\u7a0d\u540e\u5904\u7406\u5b83\u3002 \u793a\u4f8b\uff1a \u8003\u8651\u4ee5\u4e0b\u4ee3\u7801\uff1a let name = &#8220;John&#8221;; [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[],"class_list":["post-3137","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/3137","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=3137"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/3137\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=3137"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=3137"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=3137"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}