{"id":1735,"date":"2024-11-10T13:33:57","date_gmt":"2024-11-10T05:33:57","guid":{"rendered":"https:\/\/fwq.ai\/blog\/1735\/"},"modified":"2024-11-10T13:33:57","modified_gmt":"2024-11-10T05:33:57","slug":"%e4%b8%ba%e4%bb%80%e4%b9%88-js-%e5%af%b9%e8%b1%a1%e5%b1%9e%e6%80%a7%e4%b8%ad%e8%b0%83%e7%94%a8%e6%96%b9%e6%b3%95%e4%bc%9a%e6%8a%a5%e9%94%99%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/1735\/","title":{"rendered":"\u4e3a\u4ec0\u4e48 JS \u5bf9\u8c61\u5c5e\u6027\u4e2d\u8c03\u7528\u65b9\u6cd5\u4f1a\u62a5\u9519\uff1f"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/001\/246\/273\/173054629850779.jpg\" class=\"aligncenter\" title=\"\u4e3a\u4ec0\u4e48 JS \u5bf9\u8c61\u5c5e\u6027\u4e2d\u8c03\u7528\u65b9\u6cd5\u4f1a\u62a5\u9519\uff1f\u63d2\u56fe\" alt=\"\u4e3a\u4ec0\u4e48 JS \u5bf9\u8c61\u5c5e\u6027\u4e2d\u8c03\u7528\u65b9\u6cd5\u4f1a\u62a5\u9519\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong>js \u5bf9\u8c61\u5c5e\u6027\u4e2d\u8c03\u7528\u65b9\u6cd5\u51fa\u9519\u5256\u6790<\/strong><\/p>\n<p>\u5728 javascript \u4e2d\uff0c\u5f53\u5c1d\u8bd5\u5728\u4e00\u4e2a\u5bf9\u8c61\u7684\u5c5e\u6027\u4e2d\u8c03\u7528\u65b9\u6cd5\u65f6\uff0c\u53ef\u80fd\u4f1a\u9047\u5230\u9519\u8bef\u3002\u4ee3\u7801\u793a\u4f8b\u5982\u4e0b\uff1a<\/p>\n<pre>var test = {\n  a: function() {\n    return 1;\n  },\n  fn: {\n    fn1: test.a\n  },\n  exec: function() {\n    return fn.fn1();\n  }\n};<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p>\u6267\u884c\u6b64\u4ee3\u7801\u65f6\uff0c\u4f1a\u629b\u51fa\u4ee5\u4e0b\u9519\u8bef\uff1a\u201cfn \u672a\u5b9a\u4e49\u201d\u3002\u8fd9\u662f\u56e0\u4e3a test \u5bf9\u8c61\u4e2d\u7684 fn \u5c5e\u6027\u5c1a\u672a\u89e3\u6790\u5b8c\u6210\uff0c\u65e0\u6cd5\u76f4\u63a5\u5f15\u7528\u5176 test.a() \u65b9\u6cd5\u3002<\/p>\n<p>\u4e3a\u4e86\u89e3\u51b3\u8fd9\u4e2a\u95ee\u9898\uff0c\u53ef\u4ee5\u91c7\u7528\u4ee5\u4e0b\u65b9\u5f0f\u91cd\u5199\u4ee3\u7801\uff1a<\/p>\n<pre>var test = {\n  a: function() {\n    return 1;\n  }\n};\n\ntest.fn = {\n  fn1: test.a\n};\n\ntest.exec = function() {\n  return test.fn.fn1();\n};\n\nconsole.log(test.exec())<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p>\u901a\u8fc7\u5ef6\u8fdf\u89e3\u6790 fn \u5c5e\u6027\uff0c\u786e\u4fdd test \u5bf9\u8c61\u4e2d\u7684\u6240\u6709\u6210\u5458\u90fd\u5df2\u5c31\u7eea\uff0c\u8fd9\u6837\u5c31\u53ef\u4ee5\u5728 test.exec() \u65b9\u6cd5\u4e2d\u6b63\u786e\u8c03\u7528 fn.fn1() \u65b9\u6cd5\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u4e3a\u4ec0\u4e48 JS \u5bf9\u8c61\u5c5e\u6027\u4e2d\u8c03\u7528\u65b9\u6cd5\u4f1a\u62a5\u9519\uff1f\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>js \u5bf9\u8c61\u5c5e\u6027\u4e2d\u8c03\u7528\u65b9\u6cd5\u51fa\u9519\u5256\u6790 \u5728 javascript \u4e2d\uff0c\u5f53\u5c1d\u8bd5\u5728\u4e00\u4e2a\u5bf9\u8c61\u7684\u5c5e\u6027\u4e2d\u8c03\u7528\u65b9\u6cd5\u65f6\uff0c\u53ef\u80fd\u4f1a\u9047\u5230\u9519\u8bef\u3002\u4ee3\u7801\u793a\u4f8b\u5982\u4e0b\uff1a var test = { a: function() { return 1; }, fn: { fn1: test.a }, exec: function() { return fn.fn1(); } }; \u767b\u5f55\u540e\u590d\u5236 \u6267\u884c\u6b64\u4ee3\u7801\u65f6\uff0c\u4f1a\u629b\u51fa\u4ee5\u4e0b\u9519\u8bef\uff1a\u201cfn \u672a\u5b9a\u4e49\u201d\u3002\u8fd9\u662f\u56e0\u4e3a test \u5bf9\u8c61\u4e2d\u7684 fn \u5c5e\u6027\u5c1a\u672a\u89e3\u6790\u5b8c\u6210\uff0c\u65e0\u6cd5\u76f4\u63a5\u5f15\u7528\u5176 test.a() \u65b9\u6cd5\u3002 \u4e3a\u4e86\u89e3\u51b3\u8fd9\u4e2a\u95ee\u9898\uff0c\u53ef\u4ee5\u91c7\u7528\u4ee5\u4e0b\u65b9\u5f0f\u91cd\u5199\u4ee3\u7801\uff1a var test = { a: function() { return 1; } }; test.fn = { fn1: test.a }; test.exec [&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-1735","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/1735","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=1735"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/1735\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=1735"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=1735"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=1735"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}