{"id":5456,"date":"2023-01-05T12:42:25","date_gmt":"2023-01-05T04:42:25","guid":{"rendered":"https:\/\/badgameshow.com\/steven\/?p=5456"},"modified":"2023-01-05T12:42:25","modified_gmt":"2023-01-05T04:42:25","slug":"%e4%ba%86%e8%a7%a3typescript%e4%b8%ad%e7%9a%84functions%e5%8a%9f%e8%83%bd%ef%bc%9a%e6%b7%b1%e5%85%a5%e6%8e%a2%e7%b4%a2%e5%87%bd%e6%95%b8%e7%9a%84%e5%a8%81%e5%8a%9b","status":"publish","type":"post","link":"https:\/\/badgameshow.com\/steven\/typescript\/%e4%ba%86%e8%a7%a3typescript%e4%b8%ad%e7%9a%84functions%e5%8a%9f%e8%83%bd%ef%bc%9a%e6%b7%b1%e5%85%a5%e6%8e%a2%e7%b4%a2%e5%87%bd%e6%95%b8%e7%9a%84%e5%a8%81%e5%8a%9b\/","title":{"rendered":"\u4e86\u89e3TypeScript\u4e2d\u7684Functions\u529f\u80fd\uff1a\u6df1\u5165\u63a2\u7d22\u51fd\u6578\u7684\u5a01\u529b"},"content":{"rendered":"<p><meta name=\"keywords\" content=\"TypeScript, functions\"><\/p>\n<p>TypeScript \u662f\u4e00\u7a2e JavaScript \u7684\u8d85\u96c6\uff0c\u5b83\u64c1\u6709\u66f4\u591a\u7684\u529f\u80fd\uff0c\u5176\u4e2d\u4e4b\u4e00\u5c31\u662f\u51fd\u6578\u3002\u51fd\u6578\u662f TypeScript \u7a0b\u5f0f\u8a2d\u8a08\u7684\u57fa\u790e\uff0c\u5b83\u53ef\u4ee5\u8b93\u958b\u767c\u8005\u66f4\u5bb9\u6613\u5730\u64b0\u5beb\u7a0b\u5f0f\u78bc\uff0c\u4e26\u4e14\u66f4\u5bb9\u6613\u7dad\u8b77\u548c\u7ba1\u7406\u3002<\/p>\n<h2>\u4ec0\u9ebc\u662f\u51fd\u6578\uff1f<\/h2>\n<p>\u51fd\u6578\u662f\u4e00\u7a2e\u53ef\u4ee5\u57f7\u884c\u7279\u5b9a\u4efb\u52d9\u7684\u7a0b\u5f0f\u78bc\u584a\uff0c\u5b83\u53ef\u4ee5\u63a5\u53d7\u53c3\u6578\uff0c\u4e26\u4e14\u53ef\u4ee5\u50b3\u56de\u4e00\u500b\u503c\u3002\u51fd\u6578\u53ef\u4ee5\u88ab\u91cd\u8907\u4f7f\u7528\uff0c\u53ef\u4ee5\u88ab\u653e\u7f6e\u5728\u4e0d\u540c\u7684\u7a0b\u5f0f\u78bc\u584a\u4e2d\uff0c\u4e26\u4e14\u53ef\u4ee5\u88ab\u5176\u4ed6\u51fd\u6578\u547c\u53eb\u3002<\/p>\n<h2>TypeScript \u4e2d\u7684\u51fd\u6578<\/h2>\n<p>TypeScript \u4e2d\u7684\u51fd\u6578\u53ef\u4ee5\u88ab\u5b9a\u7fa9\u70ba\u4ee5\u4e0b\u5169\u7a2e\u985e\u578b\uff1a<\/p>\n<ul>\n<li><strong>\u51fd\u6578\u5ba3\u544a\uff1a<\/strong>\u5b83\u662f\u4e00\u7a2e\u5b9a\u7fa9\u51fd\u6578\u7684\u65b9\u5f0f\uff0c\u5b83\u53ef\u4ee5\u88ab\u653e\u7f6e\u5728\u4efb\u4f55\u5730\u65b9\uff0c\u4e26\u4e14\u53ef\u4ee5\u5728\u4efb\u4f55\u5730\u65b9\u88ab\u547c\u53eb\u3002<\/li>\n<li><strong>\u51fd\u6578\u8868\u9054\u5f0f\uff1a<\/strong>\u5b83\u662f\u4e00\u7a2e\u5b9a\u7fa9\u51fd\u6578\u7684\u65b9\u5f0f\uff0c\u5b83\u53ea\u80fd\u88ab\u653e\u7f6e\u5728\u8b8a\u6578\u5ba3\u544a\u7684\u5f8c\u9762\uff0c\u4e26\u4e14\u53ea\u80fd\u88ab\u8a72\u8b8a\u6578\u547c\u53eb\u3002<\/li>\n<\/ul>\n<h2>\u7bc4\u4f8b\uff1a\u4f7f\u7528\u51fd\u6578\u5ba3\u544a<\/h2>\n<p>\u4ee5\u4e0b\u662f\u4e00\u500b\u4f7f\u7528\u51fd\u6578\u5ba3\u544a\u7684\u7bc4\u4f8b\uff1a<\/p>\n<pre class=\"brush: typescript\">\nfunction add(x: number, y: number): number {\n    return x + y;\n}\n\nlet result = add(1, 2);\nconsole.log(result); \/\/ 3\n<\/pre>\n<p>\u5728\u9019\u500b\u7bc4\u4f8b\u4e2d\uff0c\u6211\u5011\u5b9a\u7fa9\u4e86\u4e00\u500b\u540d\u70ba add \u7684\u51fd\u6578\uff0c\u5b83\u63a5\u53d7\u5169\u500b\u53c3\u6578\uff0c\u4e26\u4e14\u50b3\u56de\u5169\u500b\u53c3\u6578\u7684\u548c\u3002<\/p>\n<h2>\u7bc4\u4f8b\uff1a\u4f7f\u7528\u51fd\u6578\u8868\u9054\u5f0f<\/h2>\n<p>\u4ee5\u4e0b\u662f\u4e00\u500b\u4f7f\u7528\u51fd\u6578\u8868\u9054\u5f0f\u7684\u7bc4\u4f8b\uff1a<\/p>\n<pre class=\"brush: typescript\">\nlet subtract = function(x: number, y: number): number {\n    return x - y;\n}\n\nlet result = subtract(3, 1);\nconsole.log(result); \/\/ 2\n<\/pre>\n<p>\u5728\u9019\u500b\u7bc4\u4f8b\u4e2d\uff0c\u6211\u5011\u5b9a\u7fa9\u4e86\u4e00\u500b\u540d\u70ba subtract \u7684\u51fd\u6578\uff0c\u5b83\u63a5\u53d7\u5169\u500b\u53c3\u6578\uff0c\u4e26\u4e14\u50b3\u56de\u5169\u500b\u53c3\u6578\u7684\u5dee\u3002<\/p>\n<p><!--more--><\/p>\n<h2>\u7e3d\u7d50<\/h2>\n<p>\u51fd\u6578\u662f TypeScript \u7a0b\u5f0f\u8a2d\u8a08\u7684\u57fa\u790e\uff0c\u5b83\u53ef\u4ee5\u8b93\u958b\u767c\u8005\u66f4\u5bb9\u6613\u5730\u64b0\u5beb\u7a0b\u5f0f\u78bc\uff0c\u4e26\u4e14\u66f4\u5bb9\u6613\u7dad\u8b77\u548c\u7ba1\u7406\u3002TypeScript \u4e2d\u7684\u51fd\u6578\u53ef\u4ee5\u88ab\u5b9a\u7fa9\u70ba\u51fd\u6578\u5ba3\u544a\u548c\u51fd\u6578\u8868\u9054\u5f0f\u5169\u7a2e\u985e\u578b\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5b78\u7fd2TypeScript\u4e2d\u7684Functions\u529f\u80fd\uff0c\u53ef\u4ee5\u8b93\u4f60\u66f4\u6df1\u5165\u5730\u4e86\u89e3\u51fd\u6578\u7684\u5a01\u529b\uff0c\u4e26\u66f4\u6709\u6548\u5730\u4f7f\u7528\u5b83\u5011\u4f86\u5275\u5efa\u66f4\u5f37\u5927\u7684\u61c9\u7528\u7a0b\u5e8f\u3002<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[187],"tags":[186],"class_list":["post-5456","post","type-post","status-publish","format-standard","hentry","category-typescript","tag-typescript"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack-related-posts":[],"jetpack_shortlink":"https:\/\/wp.me\/pcFK27-1q0","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts\/5456","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/comments?post=5456"}],"version-history":[{"count":1,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts\/5456\/revisions"}],"predecessor-version":[{"id":5457,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts\/5456\/revisions\/5457"}],"wp:attachment":[{"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/media?parent=5456"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/categories?post=5456"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/tags?post=5456"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}