{"id":5110,"date":"2023-01-05T11:57:54","date_gmt":"2023-01-05T03:57:54","guid":{"rendered":"https:\/\/badgameshow.com\/steven\/?p=5110"},"modified":"2023-01-05T11:57:54","modified_gmt":"2023-01-05T03:57:54","slug":"%e5%ad%b8%e7%bf%92typescript%e7%b1%bb%e7%9a%84%e6%8a%bd%e8%b1%a1%e7%b1%bb%ef%bc%9a%e6%8e%8c%e6%8f%a1%e7%a8%8b%e5%bc%8f%e9%96%8b%e7%99%bc%e7%9a%84%e5%9f%ba%e7%a4%8e","status":"publish","type":"post","link":"https:\/\/badgameshow.com\/steven\/typescript\/%e5%ad%b8%e7%bf%92typescript%e7%b1%bb%e7%9a%84%e6%8a%bd%e8%b1%a1%e7%b1%bb%ef%bc%9a%e6%8e%8c%e6%8f%a1%e7%a8%8b%e5%bc%8f%e9%96%8b%e7%99%bc%e7%9a%84%e5%9f%ba%e7%a4%8e\/","title":{"rendered":"\u5b78\u7fd2TypeScript\u7c7b\u7684\u62bd\u8c61\u7c7b\uff1a\u638c\u63e1\u7a0b\u5f0f\u958b\u767c\u7684\u57fa\u790e"},"content":{"rendered":"<p><meta name=\"keywords\" content=\"TypeScript, Classes, Abstract Class\"><\/p>\n<h1>\u4f7f\u7528 TypeScript \u7c7b(classes)\u7684\u62bd\u8c61\u7c7b<\/h1>\n<p>TypeScript \u662f\u4e00\u7a2e JavaScript \u7684\u8d85\u96c6\uff0c\u5b83\u63d0\u4f9b\u4e86\u66f4\u591a\u7684\u529f\u80fd\uff0c\u4f8b\u5982\u985e\u5225(classes)\u3001\u63a5\u53e3(interfaces)\u3001\u6a21\u584a(modules)\u7b49\u3002\u5176\u4e2d\uff0c\u62bd\u8c61\u985e\u5225(abstract classes)\u662f\u4e00\u7a2e\u7279\u6b8a\u7684\u985e\u5225\uff0c\u5b83\u53ef\u4ee5\u88ab\u7528\u4f86\u5b9a\u7fa9\u4e00\u500b\u62bd\u8c61\u7684\u6982\u5ff5\uff0c\u800c\u4e0d\u662f\u5be6\u969b\u7684\u7269\u4ef6\u3002<\/p>\n<p>\u62bd\u8c61\u985e\u5225\u662f\u4e00\u7a2e\u4e0d\u80fd\u88ab\u5be6\u4f8b\u5316\u7684\u985e\u5225\uff0c\u5b83\u53ea\u80fd\u88ab\u7528\u4f86\u5b9a\u7fa9\u4e00\u500b\u62bd\u8c61\u7684\u6982\u5ff5\uff0c\u800c\u4e0d\u662f\u5be6\u969b\u7684\u7269\u4ef6\u3002\u5b83\u53ef\u4ee5\u5305\u542b\u62bd\u8c61\u65b9\u6cd5\uff0c\u62bd\u8c61\u5c6c\u6027\u548c\u5177\u9ad4\u7684\u5c6c\u6027\u548c\u65b9\u6cd5\u3002\u62bd\u8c61\u985e\u5225\u53ef\u4ee5\u88ab\u7528\u4f86\u5b9a\u7fa9\u4e00\u500b\u62bd\u8c61\u7684\u6982\u5ff5\uff0c\u800c\u4e0d\u662f\u5be6\u969b\u7684\u7269\u4ef6\uff0c\u5b83\u53ef\u4ee5\u88ab\u7528\u4f86\u5b9a\u7fa9\u4e00\u500b\u62bd\u8c61\u7684\u6982\u5ff5\uff0c\u800c\u4e0d\u662f\u5be6\u969b\u7684\u7269\u4ef6\u3002<\/p>\n<p><!--more--><\/p>\n<p>\u62bd\u8c61\u985e\u5225\u53ef\u4ee5\u88ab\u7528\u4f86\u5b9a\u7fa9\u4e00\u500b\u62bd\u8c61\u7684\u6982\u5ff5\uff0c\u800c\u4e0d\u662f\u5be6\u969b\u7684\u7269\u4ef6\u3002\u5b83\u53ef\u4ee5\u5305\u542b\u62bd\u8c61\u65b9\u6cd5\uff0c\u62bd\u8c61\u5c6c\u6027\u548c\u5177\u9ad4\u7684\u5c6c\u6027\u548c\u65b9\u6cd5\u3002\u62bd\u8c61\u985e\u5225\u53ef\u4ee5\u88ab\u7528\u4f86\u5b9a\u7fa9\u4e00\u500b\u62bd\u8c61\u7684\u6982\u5ff5\uff0c\u800c\u4e0d\u662f\u5be6\u969b\u7684\u7269\u4ef6\uff0c\u5b83\u53ef\u4ee5\u88ab\u7528\u4f86\u5b9a\u7fa9\u4e00\u500b\u62bd\u8c61\u7684\u6982\u5ff5\uff0c\u800c\u4e0d\u662f\u5be6\u969b\u7684\u7269\u4ef6\u3002<\/p>\n<p>\u62bd\u8c61\u985e\u5225\u53ef\u4ee5\u88ab\u7528\u4f86\u5b9a\u7fa9\u4e00\u500b\u62bd\u8c61\u7684\u6982\u5ff5\uff0c\u800c\u4e0d\u662f\u5be6\u969b\u7684\u7269\u4ef6\u3002\u5b83\u53ef\u4ee5\u5305\u542b\u62bd\u8c61\u65b9\u6cd5\uff0c\u62bd\u8c61\u5c6c\u6027\u548c\u5177\u9ad4\u7684\u5c6c\u6027\u548c\u65b9\u6cd5\u3002\u62bd\u8c61\u985e\u5225\u53ef\u4ee5\u88ab\u7528\u4f86\u5b9a\u7fa9\u4e00\u500b\u62bd\u8c61\u7684\u6982\u5ff5\uff0c\u800c\u4e0d\u662f\u5be6\u969b\u7684\u7269\u4ef6\uff0c\u5b83\u53ef\u4ee5\u88ab\u7528\u4f86\u5b9a\u7fa9\u4e00\u500b\u62bd\u8c61\u7684\u6982\u5ff5\uff0c\u800c\u4e0d\u662f\u5be6\u969b\u7684\u7269\u4ef6\u3002<\/p>\n<p>\u8209\u4f8b\u4f86\u8aaa\uff0c\u5047\u8a2d\u6211\u5011\u60f3\u8981\u5b9a\u7fa9\u4e00\u500b\u62bd\u8c61\u7684\u300c\u52d5\u7269\u300d\u985e\u5225\uff0c\u6211\u5011\u53ef\u4ee5\u4f7f\u7528 TypeScript \u7684\u62bd\u8c61\u985e\u5225\u4f86\u5b9a\u7fa9\u5b83\uff1a<\/p>\n<pre class=\"brush: typescript\">\nabstract class Animal {\n    abstract makeSound(): void;\n    move(): void {\n        console.log('roaming the earth...');\n    }\n}\n<\/pre>\n<p>\u5728\u4e0a\u9762\u7684\u7bc4\u4f8b\u4e2d\uff0c\u6211\u5011\u5b9a\u7fa9\u4e86\u4e00\u500b\u62bd\u8c61\u985e\u5225 Animal\uff0c\u5b83\u5305\u542b\u4e00\u500b\u62bd\u8c61\u65b9\u6cd5 makeSound() \u548c\u4e00\u500b\u5177\u9ad4\u7684\u65b9\u6cd5 move()\u3002\u62bd\u8c61\u65b9\u6cd5 makeSound() \u5fc5\u9808\u88ab\u5b50\u985e\u5225\u5be6\u73fe\uff0c\u800c move() \u65b9\u6cd5\u5247\u53ef\u4ee5\u88ab\u5b50\u985e\u5225\u7e7c\u627f\u3002<\/p>\n<p>\u62bd\u8c61\u985e\u5225\u662f\u4e00\u7a2e\u975e\u5e38\u6709\u7528\u7684\u5de5\u5177\uff0c\u5b83\u53ef\u4ee5\u88ab\u7528\u4f86\u5b9a\u7fa9\u4e00\u500b\u62bd\u8c61\u7684\u6982\u5ff5\uff0c\u800c\u4e0d\u662f\u5be6\u969b\u7684\u7269\u4ef6\u3002\u5b83\u53ef\u4ee5\u88ab\u7528\u4f86\u5b9a\u7fa9\u4e00\u500b\u62bd\u8c61\u7684\u6982\u5ff5\uff0c\u800c\u4e0d\u662f\u5be6\u969b\u7684\u7269\u4ef6\uff0c\u5b83\u53ef\u4ee5\u88ab\u7528\u4f86\u5b9a\u7fa9\u4e00\u500b\u62bd\u8c61\u7684\u6982\u5ff5\uff0c\u800c\u4e0d\u662f\u5be6\u969b\u7684\u7269\u4ef6\u3002\u4f7f\u7528 TypeScript \u7684\u62bd\u8c61\u985e\u5225\uff0c\u53ef\u4ee5\u8b93\u958b\u767c\u8005\u66f4\u5bb9\u6613\u5730\u5b9a\u7fa9\u4e00\u500b\u62bd\u8c61\u7684\u6982\u5ff5\uff0c\u800c\u4e0d\u662f\u5be6\u969b\u7684\u7269\u4ef6\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6587\u7ae0\u6458\u8981\uff1aTypeScript\u7c7b\u7684\u62bd\u8c61\u7c7b\u662f\u7a0b\u5f0f\u958b\u767c\u7684\u57fa\u790e\uff0c\u53ef\u4ee5\u8b93\u958b\u767c\u8005\u66f4\u5bb9\u6613\u5730\u69cb\u5efa\u548c\u7ba1\u7406\u7a0b\u5f0f\u78bc\u3002\u672c\u6587\u5c07\u4ecb\u7d39TypeScript\u7c7b\u7684\u62bd\u8c61\u7c7b\u7684\u6982\u5ff5\uff0c\u4ee5\u53ca\u5982\u4f55\u4f7f\u7528\u5b83\u4f86\u69cb\u5efa\u548c\u7ba1\u7406\u7a0b\u5f0f\u78bc\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-5110","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-1kq","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts\/5110","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=5110"}],"version-history":[{"count":1,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts\/5110\/revisions"}],"predecessor-version":[{"id":5111,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts\/5110\/revisions\/5111"}],"wp:attachment":[{"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/media?parent=5110"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/categories?post=5110"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/tags?post=5110"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}