{"id":5134,"date":"2023-01-05T12:01:08","date_gmt":"2023-01-05T04:01:08","guid":{"rendered":"https:\/\/badgameshow.com\/steven\/?p=5134"},"modified":"2023-01-05T12:01:08","modified_gmt":"2023-01-05T04:01:08","slug":"%e5%ad%b8%e7%bf%92typescript%e5%87%bd%e6%95%b8%e7%9a%84%e5%9f%ba%e6%9c%ac%e7%94%a8%e6%b3%95","status":"publish","type":"post","link":"https:\/\/badgameshow.com\/steven\/typescript\/%e5%ad%b8%e7%bf%92typescript%e5%87%bd%e6%95%b8%e7%9a%84%e5%9f%ba%e6%9c%ac%e7%94%a8%e6%b3%95\/","title":{"rendered":"\u5b78\u7fd2TypeScript\u51fd\u6578\u7684\u57fa\u672c\u7528\u6cd5"},"content":{"rendered":"<p><meta name=\"keywords\" content=\"TypeScript, Functions, \u7528\u6cd5\"><\/p>\n<h1>TypeScript \u51fd\u6578(Functions)\u7684\u57fa\u672c\u7528\u6cd5<\/h1>\n<p>TypeScript \u662f\u4e00\u7a2e JavaScript \u7684\u8d85\u96c6\uff0c\u5b83\u64c1\u6709 JavaScript \u7684\u6240\u6709\u529f\u80fd\uff0c\u4e26\u4e14\u63d0\u4f9b\u4e86\u984d\u5916\u7684\u7279\u6027\uff0c\u4f8b\u5982\u985e\u578b\u6aa2\u67e5\u548c\u975c\u614b\u578b\u5225\u7cfb\u7d71\u3002\u5728 TypeScript \u4e2d\uff0c\u51fd\u6578\u662f\u4e00\u7a2e\u91cd\u8981\u7684\u6982\u5ff5\uff0c\u5b83\u53ef\u4ee5\u8b93\u958b\u767c\u8005\u66f4\u5bb9\u6613\u5730\u64b0\u5beb\u548c\u7dad\u8b77\u7a0b\u5f0f\u78bc\u3002\u672c\u6587\u5c07\u4ecb\u7d39 TypeScript \u51fd\u6578\u7684\u57fa\u672c\u7528\u6cd5\uff0c\u4e26\u63d0\u4f9b\u4e00\u4e9b\u7bc4\u4f8b\u4f86\u8aaa\u660e\u3002<\/p>\n<p><!--more--><\/p>\n<p>TypeScript \u51fd\u6578\u53ef\u4ee5\u5206\u70ba\u5169\u7a2e\uff1a\u51fd\u6578\u5ba3\u544a\u548c\u51fd\u6578\u8868\u9054\u5f0f\u3002\u51fd\u6578\u5ba3\u544a\u662f\u4e00\u7a2e\u5b9a\u7fa9\u51fd\u6578\u7684\u65b9\u5f0f\uff0c\u5b83\u53ef\u4ee5\u8b93\u958b\u767c\u8005\u66f4\u5bb9\u6613\u5730\u5b9a\u7fa9\u51fd\u6578\uff0c\u4e26\u4e14\u53ef\u4ee5\u5728\u51fd\u6578\u5ba3\u544a\u4e4b\u524d\u4f7f\u7528\u51fd\u6578\u3002\u51fd\u6578\u8868\u9054\u5f0f\u5247\u662f\u4e00\u7a2e\u5b9a\u7fa9\u51fd\u6578\u7684\u53e6\u4e00\u7a2e\u65b9\u5f0f\uff0c\u5b83\u53ef\u4ee5\u8b93\u958b\u767c\u8005\u66f4\u5bb9\u6613\u5730\u5b9a\u7fa9\u51fd\u6578\uff0c\u4e26\u4e14\u53ef\u4ee5\u5728\u51fd\u6578\u8868\u9054\u5f0f\u4e4b\u5f8c\u4f7f\u7528\u51fd\u6578\u3002<\/p>\n<h2>\u51fd\u6578\u5ba3\u544a<\/h2>\n<p>\u51fd\u6578\u5ba3\u544a\u662f\u4e00\u7a2e\u5b9a\u7fa9\u51fd\u6578\u7684\u65b9\u5f0f\uff0c\u5b83\u53ef\u4ee5\u8b93\u958b\u767c\u8005\u66f4\u5bb9\u6613\u5730\u5b9a\u7fa9\u51fd\u6578\uff0c\u4e26\u4e14\u53ef\u4ee5\u5728\u51fd\u6578\u5ba3\u544a\u4e4b\u524d\u4f7f\u7528\u51fd\u6578\u3002\u51fd\u6578\u5ba3\u544a\u7684\u8a9e\u6cd5\u5982\u4e0b\uff1a<\/p>\n<pre class=\"brush: typescript\">\nfunction functionName(parameter1, parameter2, ...) {\n    \/\/ function body\n}\n<\/pre>\n<p>\u51fd\u6578\u5ba3\u544a\u7684\u53c3\u6578\u53ef\u4ee5\u662f\u4efb\u4f55\u985e\u578b\uff0c\u4f8b\u5982\u5b57\u4e32\u3001\u6578\u5b57\u3001\u5e03\u6797\u503c\u7b49\u3002\u51fd\u6578\u5ba3\u544a\u7684\u51fd\u6578\u9ad4\u53ef\u4ee5\u5305\u542b\u4efb\u4f55\u6709\u6548\u7684 TypeScript \u4ee3\u78bc\uff0c\u4f8b\u5982\u8b8a\u6578\u5ba3\u544a\u3001\u689d\u4ef6\u5224\u65b7\u3001\u8ff4\u5708\u7b49\u3002<\/p>\n<h2>\u51fd\u6578\u8868\u9054\u5f0f<\/h2>\n<p>\u51fd\u6578\u8868\u9054\u5f0f\u662f\u4e00\u7a2e\u5b9a\u7fa9\u51fd\u6578\u7684\u53e6\u4e00\u7a2e\u65b9\u5f0f\uff0c\u5b83\u53ef\u4ee5\u8b93\u958b\u767c\u8005\u66f4\u5bb9\u6613\u5730\u5b9a\u7fa9\u51fd\u6578\uff0c\u4e26\u4e14\u53ef\u4ee5\u5728\u51fd\u6578\u8868\u9054\u5f0f\u4e4b\u5f8c\u4f7f\u7528\u51fd\u6578\u3002\u51fd\u6578\u8868\u9054\u5f0f\u7684\u8a9e\u6cd5\u5982\u4e0b\uff1a<\/p>\n<pre class=\"brush: typescript\">\nlet functionName = function(parameter1, parameter2, ...) {\n    \/\/ function body\n}\n<\/pre>\n<p>\u51fd\u6578\u8868\u9054\u5f0f\u7684\u53c3\u6578\u53ef\u4ee5\u662f\u4efb\u4f55\u985e\u578b\uff0c\u4f8b\u5982\u5b57\u4e32\u3001\u6578\u5b57\u3001\u5e03\u6797\u503c\u7b49\u3002\u51fd\u6578\u8868\u9054\u5f0f\u7684\u51fd\u6578\u9ad4\u53ef\u4ee5\u5305\u542b\u4efb\u4f55\u6709\u6548\u7684 TypeScript \u4ee3\u78bc\uff0c\u4f8b\u5982\u8b8a\u6578\u5ba3\u544a\u3001\u689d\u4ef6\u5224\u65b7\u3001\u8ff4\u5708\u7b49\u3002<\/p>\n<h2>\u7bc4\u4f8b<\/h2>\n<p>\u4ee5\u4e0b\u662f\u4e00\u500b\u7c21\u55ae\u7684 TypeScript \u51fd\u6578\u7bc4\u4f8b\uff1a<\/p>\n<pre class=\"brush: typescript\">\n\/\/ \u51fd\u6578\u5ba3\u544a\nfunction add(x: number, y: number): number {\n    return x + y;\n}\n\n\/\/ \u51fd\u6578\u8868\u9054\u5f0f\nlet subtract = function(x: number, y: number): number {\n    return x - y;\n}\n\n\/\/ \u4f7f\u7528\u51fd\u6578\nlet result1 = add(1, 2);\nlet result2 = subtract(1, 2);\n\nconsole.log(result1); \/\/ 3\nconsole.log(result2); \/\/ -1\n<\/pre>\n<p>\u5728\u4e0a\u9762\u7684\u7bc4\u4f8b\u4e2d\uff0c\u6211\u5011\u5b9a\u7fa9\u4e86\u4e00\u500b\u540d\u70ba add \u7684\u51fd\u6578\u5ba3\u544a\uff0c\u5b83\u63a5\u53d7\u5169\u500b\u53c3\u6578\uff0c\u4e26\u8fd4\u56de\u5169\u500b\u53c3\u6578\u7684\u548c\u3002\u6211\u5011\u4e5f\u5b9a\u7fa9\u4e86\u4e00\u500b\u540d\u70ba subtract \u7684\u51fd\u6578\u8868\u9054\u5f0f\uff0c\u5b83\u63a5\u53d7\u5169\u500b\u53c3\u6578\uff0c\u4e26\u8fd4\u56de\u5169\u500b\u53c3\u6578\u7684\u5dee\u3002\u6700\u5f8c\uff0c\u6211\u5011\u4f7f\u7528\u9019\u5169\u500b\u51fd\u6578\u4f86\u8a08\u7b97\u7d50\u679c\uff0c\u4e26\u5c07\u7d50\u679c\u8f38\u51fa\u5230\u63a7\u5236\u53f0\u3002<\/p>\n<h2>\u7e3d\u7d50<\/h2>\n<p>\u672c\u6587\u4ecb\u7d39\u4e86 TypeScript \u51fd\u6578\u7684\u57fa\u672c\u7528\u6cd5\uff0c\u4e26\u63d0\u4f9b\u4e86\u4e00\u500b\u7c21\u55ae\u7684\u7bc4\u4f8b\u4f86\u8aaa\u660e\u3002\u51fd\u6578\u5ba3\u544a\u548c\u51fd\u6578\u8868\u9054\u5f0f\u90fd\u662f\u5b9a\u7fa9\u51fd\u6578\u7684\u6709\u6548\u65b9\u5f0f\uff0c\u5b83\u5011\u53ef\u4ee5\u8b93\u958b\u767c\u8005\u66f4\u5bb9\u6613\u5730\u64b0\u5beb\u548c\u7dad\u8b77\u7a0b\u5f0f\u78bc\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6587\u7ae0\u6458\u8981\uff1a\u672c\u6587\u5c07\u4ecb\u7d39TypeScript\u51fd\u6578\u7684\u57fa\u672c\u7528\u6cd5\uff0c\u5305\u62ec\u5b9a\u7fa9\u51fd\u6578\u3001\u53c3\u6578\u3001\u56de\u50b3\u503c\u7b49\uff0c\u8b93\u8b80\u8005\u80fd\u5920\u66f4\u52a0\u4e86\u89e3TypeScript\u51fd\u6578\u7684\u529f\u80fd\u8207\u7528\u6cd5\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-5134","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-1kO","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts\/5134","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=5134"}],"version-history":[{"count":1,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts\/5134\/revisions"}],"predecessor-version":[{"id":5135,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts\/5134\/revisions\/5135"}],"wp:attachment":[{"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/media?parent=5134"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/categories?post=5134"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/tags?post=5134"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}