{"id":1176,"date":"2022-05-16T10:57:13","date_gmt":"2022-05-16T02:57:13","guid":{"rendered":"http:\/\/zhuxinyong.com\/?p=1176"},"modified":"2022-05-17T14:21:18","modified_gmt":"2022-05-17T06:21:18","slug":"ce-lue-mo-shi","status":"publish","type":"post","link":"https:\/\/zhuxinyong.com\/?p=1176","title":{"rendered":"\u7b56\u7565\u6a21\u5f0f"},"content":{"rendered":"<p><img decoding=\"async\" src=\"http:\/\/zhuxinyong.com\/wp-content\/uploads\/2022\/05\/2022-05-1611_54_58.png\" alt=\"2022-05-16+11_54_58\" \/><\/p>\n<p>\u5b9a\u4e49\uff1a<\/p>\n<blockquote>\n<p>\u5b9a\u4e49\u4e00\u7cfb\u5217\u7684\u7b97\u6cd5\uff0c\u628a\u5b83\u4eec\u4e00\u4e2a\u4e2a\u5c01\u88c5\u8d77\u6765\uff0c\u5e76\u4e14\u4f7f\u5b83\u4eec\u53ef\u4ee5\u76f8\u4e92\u66ff\u6362\u3002<\/p>\n<\/blockquote>\n<h3><a id=\"%E5%AE%9E%E7%8E%B0%E7%AD%96%E7%95%A5%E6%A8%A1%E5%BC%8F\" class=\"anchor\" aria-hidden=\"true\"><span class=\"octicon octicon-link\"><\/span><\/a>\u5b9e\u73b0\u7b56\u7565\u6a21\u5f0f<\/h3>\n<p>\u7b56\u7565\u6a21\u5f0f\u4e0d\u597d\u76f4\u63a5\u7528\u4ee3\u7801\u6765\u8bf4\uff0c\u800c\u662f\u5148\u4e3e\u4e00\u4e9b\u4f8b\u5b50\u3002<\/p>\n<p>\u6bd4\u5982\u53bb\u65c5\u6e38\u9009\u62e9\u4ea4\u901a\u5de5\u5177\uff1a<\/p>\n<p><img decoding=\"async\" src=\"http:\/\/zhuxinyong.com\/wp-content\/uploads\/2022\/05\/16527511732140.jpg\" alt=\"\" \/><\/p>\n<p>\u4e0a\u9762\u7684\u51e0\u79cd\u65b9\u5f0f\u90fd\u53ef\u4ee5\u628a\u4f60\u5e26\u5230\u76ee\u7684\u5730\uff0c\u6839\u636e\u4e2a\u4eba\u5b9e\u9645\u9700\u6c42\u53ef\u4ee5\u76f8\u4e92\u66ff\u6362\u3002<\/p>\n<p>\u8fd8\u6709\u6839\u636e\u7ee9\u6548\u7b97\u5e74\u7ec8\u5956\uff1a<\/p>\n<p><img decoding=\"async\" src=\"http:\/\/zhuxinyong.com\/wp-content\/uploads\/2022\/05\/16527513427995.jpg\" alt=\"\" \/><\/p>\n<p>\u6839\u636e\u4e0d\u540c\u7684\u8bc4\u5206\u7b49\u7ea7\uff0c\u8ba1\u7b97\u4e0d\u540c\u7684\u5e74\u7ec8\u5956\u3002<\/p>\n<pre class=\"line-numbers\"><code class=\"language-plain_text\">function getBonus(level, salary) {\n  if (level === 'S') {\n    return salary * 4\n  } else if (level === 'A') {\n    return salary * 3\n  } else if (level === 'B') {\n    return salary * 2\n  } else if (level === 'C') {\n    return salary * 1\n  }\n}\n<\/code><\/pre>\n<p>\u8fd9\u6bb5\u4ee3\u7801\uff1a<\/p>\n<ol>\n<li>\u65e2\u6709\u5224\u65ad\u7b49\u7ea7\u7684\u903b\u8f91\u53c8\u6709\u8ba1\u7b97\u5956\u91d1\u7684\u903b\u8f91\uff0c\u8fdd\u53cd\u4e86\u5355\u4e00\u804c\u8d23\uff1b<\/li>\n<li>\u82e5\u54ea\u5929\u9700\u8981\u52a0\u53e6\u4e00\u4e2a\u7b49\u7ea7 D \u9700\u8981\u76f4\u63a5\u5728\u51fd\u6570\u91cc\u9762\u4fee\u6539\uff0c\u8fdd\u53cd\u4e86\u5f00\u95ed\u539f\u5219\uff1b<\/li>\n<li>\u5982\u679c\u9700\u8981\u5728\u522b\u7684\u5730\u65b9\u4f7f\u7528\u5176\u4e2d\u4e00\u4e2a\u7b49\u7ea7\uff0c\u53ea\u80fd C \/ V \u5927\u6cd5\uff0c\u6ca1\u6709\u590d\u7528\u6027\u3002<\/li>\n<\/ol>\n<p>\u91cd\u65b0\u66f4\u6539\u4e0a\u9762\u4ee3\u7801\uff1a<\/p>\n<ol>\n<li>\u62c6\u5206<\/li>\n<\/ol>\n<pre class=\"line-numbers\"><code class=\"language-plain_text\">function sLevel(salary) {\n  return salary * 4\n}\n\nfunction aLevel(salary) {\n  return salary * 3\n}\n\nfunction bLevel(salary) {\n  return salary * 2\n}\n\nfunction cLevel(salary) {\n  return salary * 1\n}\n\nfunction getBonus(level, salary) {\n  if (level === 'S') {\n    return sLevel(salary)\n  } else if (level === 'A') {\n    return aLevel(salary)\n  } else if (level === 'B') {\n    return bLevel(salary)\n  } else if (level === 'C') {\n    return cLevel(salary)\n  }\n}\n\ngetBonus('S',1000)\n<\/code><\/pre>\n<p>\u7ecf\u8fc7\u62c6\u5206\uff0c\u8ba1\u7b97\u903b\u8f91\u88ab\u62c6\u51fa\u53bb\u4e86\uff0c\u540c\u65f6\u8fbe\u5230\u4e86\u590d\u7528\u6027\u3002\u4f46\u662f\u73b0\u5728\u8fd8\u6709\u95ee\u9898\uff0c\u82e5\u6b64\u65f6\u518d\u52a0\u4e00\u4e2a\u7b49\u7ea7\uff0c\u8fd8\u662f\u9700\u8981\u5728 getBonus \u51fd\u6570\u91cc\u4fee\u6539\uff0c\u8fd8\u662f\u6ca1\u6709\u89e3\u51b3\u5f00\u95ed\u539f\u5219\u7684\u95ee\u9898\uff0c\u540c\u65f6\u4e5f\u4f1a\u9020\u6210\u8be5\u51fd\u6570\u8d8a\u6765\u8d8a\u81c3\u80bf\u3002\u53ea\u662f\u5355\u4e00\u804c\u8d23\u7684\u539f\u5219\u5f97\u5230\u4e86\u7a0d\u5fae\u6539\u5584\u3002<\/p>\n<p>\u6211\u4eec\u8981\u59cb\u7ec8\u8bb0\u4f4f\u8bbe\u8ba1\u6a21\u5f0f\u7684\u4e3b\u9898\uff1a<strong>\u5c06\u4e0d\u53d8\u7684\u90e8\u5206\u548c\u53d8\u5316\u7684\u90e8\u5206\u9694\u5f00<\/strong>\uff0c\u8fd9\u91cc\u53d8\u5316\u7684\u90e8\u5206\u662f\u8ba1\u7b97\u5956\u91d1\u7684\u903b\u8f91\uff0c\u4e0d\u53d8\u7684\u662f\u6839\u636e\u7b49\u7ea7\u8c03\u7528\u4e0d\u540c\u7684\u8ba1\u7b97\u903b\u8f91\uff0cgetBonus \u91cc\u4e3b\u8981\u662f\u5b8c\u6210\u4e86\uff1a\u7b49\u7ea7-\u8ba1\u7b97\u5956\u91d1\u51fd\u6570\u7684\u6620\u5c04\uff0c\u90a3 JavaScript \u4e2d\u5bf9\u8c61\u5177\u6709\u6620\u5c04\u80fd\u529b\uff1a<\/p>\n<pre class=\"line-numbers\"><code class=\"language-plain_text\">\nlet strategies = {\n  'S': function (salary) {\n    return salary * 4\n  },\n  'A': function (salary) {\n    return salary * 3\n  },\n  'B': function (salary) {\n    return salary * 2\n  },\n  'C': function (salary) {\n    return salary * 1\n  }\n}\n\n\nfunction getBonus(level, salary) {\n  return strategies[level](salary)\n}\n\ngetBonus('S',1000)\n<\/code><\/pre>\n<p>\u6b64\u65f6\u518d\u9700\u8981\u52a0\u7b49\u7ea7 D \u4e5f\u4e0d\u4f1a\u5230 getBonus \u4e2d\u4fee\u6539\uff0c\u6240\u4ee5\u4e5f\u4e0d\u4f1a\u589e\u52a0\u90a3\u91cc\u7684\u4ee3\u7801\u903b\u8f91\uff0c\u771f\u662f\u5b9e\u73b0\u4e86\u5355\u4e00\u804c\u8d23\u3002<\/p>\n<pre class=\"line-numbers\"><code class=\"language-plain_text\">strategies.D = function (salary) {\n  return salary * 0.9\n}\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u5b9a\u4e49\uff1a \u5b9a\u4e49\u4e00\u7cfb\u5217\u7684\u7b97\u6cd5\uff0c\u628a\u5b83\u4eec\u4e00\u4e2a\u4e2a\u5c01\u88c5\u8d77\u6765\uff0c\u5e76\u4e14\u4f7f\u5b83\u4eec\u53ef\u4ee5\u76f8\u4e92\u66ff\u6362\u3002 \u5b9e\u73b0\u7b56\u7565\u6a21\u5f0f \u7b56\u7565\u6a21\u5f0f\u4e0d\u597d&#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2,20,3],"tags":[124,123],"class_list":["post-1176","post","type-post","status-publish","format-standard","hentry","category-all","category-frontend","category-tech","tag-124","tag-123"],"_links":{"self":[{"href":"https:\/\/zhuxinyong.com\/index.php?rest_route=\/wp\/v2\/posts\/1176","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/zhuxinyong.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/zhuxinyong.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/zhuxinyong.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/zhuxinyong.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1176"}],"version-history":[{"count":1,"href":"https:\/\/zhuxinyong.com\/index.php?rest_route=\/wp\/v2\/posts\/1176\/revisions"}],"predecessor-version":[{"id":1177,"href":"https:\/\/zhuxinyong.com\/index.php?rest_route=\/wp\/v2\/posts\/1176\/revisions\/1177"}],"wp:attachment":[{"href":"https:\/\/zhuxinyong.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1176"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/zhuxinyong.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1176"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/zhuxinyong.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1176"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}