{"id":5104,"date":"2023-01-05T11:56:46","date_gmt":"2023-01-05T03:56:46","guid":{"rendered":"https:\/\/badgameshow.com\/steven\/?p=5104"},"modified":"2023-01-05T11:56:46","modified_gmt":"2023-01-05T03:56:46","slug":"%e4%ba%86%e8%a7%a3typescript%e7%b1%bb%e4%b8%ad%e7%9a%84%e9%9d%9c%e6%85%8b%e5%b1%9e%e6%80%a7%e5%92%8c%e6%96%b9%e6%b3%95","status":"publish","type":"post","link":"https:\/\/badgameshow.com\/steven\/typescript\/%e4%ba%86%e8%a7%a3typescript%e7%b1%bb%e4%b8%ad%e7%9a%84%e9%9d%9c%e6%85%8b%e5%b1%9e%e6%80%a7%e5%92%8c%e6%96%b9%e6%b3%95\/","title":{"rendered":"\u4e86\u89e3TypeScript\u7c7b\u4e2d\u7684\u975c\u614b\u5c5e\u6027\u548c\u65b9\u6cd5"},"content":{"rendered":"<p><meta name=\"keywords\" content=\"TypeScript, Classes, \u9759\u6001\u5c5e\u6027, \u9759\u6001\u65b9\u6cd5\"><\/p>\n<h1>TypeScript \u7c7b(classes)\u7684\u9759\u6001\u5c5e\u6027\u548c\u65b9\u6cd5<\/h1>\n<p>TypeScript \u662f\u4e00\u7a2e\u7531 Microsoft \u958b\u767c\u7684 JavaScript \u7684\u8d85\u96c6\uff0c\u5b83\u63d0\u4f9b\u4e86\u985e\u4f3c\u65bc Java \u7684\u985e\u5225\u7cfb\u7d71\uff0c\u53ef\u4ee5\u8b93\u958b\u767c\u8005\u66f4\u5bb9\u6613\u5730\u64b0\u5beb JavaScript \u7a0b\u5f0f\u78bc\u3002\u5728 TypeScript \u4e2d\uff0c\u958b\u767c\u8005\u53ef\u4ee5\u4f7f\u7528\u975c\u614b\u5c6c\u6027\u548c\u65b9\u6cd5\u4f86\u64f4\u5145\u985e\u5225\u7684\u529f\u80fd\u3002<\/p>\n<p><!--more--><\/p>\n<p>\u975c\u614b\u5c6c\u6027\u548c\u65b9\u6cd5\u662f\u6307\u985e\u5225\u672c\u8eab\u7684\u5c6c\u6027\u548c\u65b9\u6cd5\uff0c\u800c\u4e0d\u662f\u985e\u5225\u7684\u5be6\u4f8b\uff08\u4e5f\u5c31\u662f\u7269\u4ef6\uff09\u7684\u5c6c\u6027\u548c\u65b9\u6cd5\u3002\u975c\u614b\u5c6c\u6027\u548c\u65b9\u6cd5\u53ef\u4ee5\u88ab\u985e\u5225\u7684\u6240\u6709\u5be6\u4f8b\u5171\u4eab\uff0c\u800c\u4e0d\u9700\u8981\u6bcf\u500b\u5be6\u4f8b\u90fd\u6709\u4e00\u4efd\u8907\u672c\u3002<\/p>\n<p>\u5728 TypeScript \u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528 static \u95dc\u9375\u5b57\u4f86\u5b9a\u7fa9\u975c\u614b\u5c6c\u6027\u548c\u65b9\u6cd5\uff0c\u4f8b\u5982\uff1a<\/p>\n<pre class=\"brush: typescript\">\nclass MyClass {\n    static myStaticProperty = 'foo';\n    static myStaticMethod() {\n        console.log('Hello World!');\n    }\n}\n<\/pre>\n<p>\u4e0a\u9762\u7684\u7a0b\u5f0f\u78bc\u5b9a\u7fa9\u4e86\u4e00\u500b\u540d\u70ba MyClass \u7684\u985e\u5225\uff0c\u5b83\u6709\u4e00\u500b\u975c\u614b\u5c6c\u6027 myStaticProperty \u548c\u4e00\u500b\u975c\u614b\u65b9\u6cd5 myStaticMethod\u3002<\/p>\n<p>\u975c\u614b\u5c6c\u6027\u53ef\u4ee5\u901a\u904e\u985e\u5225\u540d\u7a31\u76f4\u63a5\u8a2a\u554f\uff0c\u4f8b\u5982\uff1a<\/p>\n<pre class=\"brush: typescript\">\nconsole.log(MyClass.myStaticProperty); \/\/ 'foo'\n<\/pre>\n<p>\u975c\u614b\u65b9\u6cd5\u4e5f\u53ef\u4ee5\u901a\u904e\u985e\u5225\u540d\u7a31\u76f4\u63a5\u8abf\u7528\uff0c\u4f8b\u5982\uff1a<\/p>\n<pre class=\"brush: typescript\">\nMyClass.myStaticMethod(); \/\/ 'Hello World!'\n<\/pre>\n<p>\u975c\u614b\u5c6c\u6027\u548c\u65b9\u6cd5\u53ef\u4ee5\u8b93\u958b\u767c\u8005\u66f4\u5bb9\u6613\u5730\u5c01\u88dd\u548c\u7ba1\u7406\u985e\u5225\u7684\u529f\u80fd\uff0c\u4e26\u4e14\u53ef\u4ee5\u6e1b\u5c11\u985e\u5225\u7684\u5be6\u4f8b\u6578\u91cf\uff0c\u5f9e\u800c\u63d0\u9ad8\u7a0b\u5f0f\u7684\u6548\u7387\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6587\u7ae0\u6458\u8981:TypeScript\u7c7b\u4e2d\u7684\u975c\u614b\u5c5e\u6027\u548c\u65b9\u6cd5\u53ef\u4ee5\u8b93\u958b\u767c\u8005\u66f4\u52a0\u6709\u6548\u5730\u7ba1\u7406\u548c\u64cd\u4f5c\u8cc7\u6599\uff0c\u672c\u6587\u5c07\u4ecb\u7d39TypeScript\u7c7b\u4e2d\u7684\u975c\u614b\u5c5e\u6027\u548c\u65b9\u6cd5\uff0c\u4ee5\u53ca\u5982\u4f55\u4f7f\u7528\u5b83\u5011\u4f86\u63d0\u9ad8\u958b\u767c\u6548\u7387\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-5104","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-1kk","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts\/5104","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=5104"}],"version-history":[{"count":1,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts\/5104\/revisions"}],"predecessor-version":[{"id":5105,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts\/5104\/revisions\/5105"}],"wp:attachment":[{"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/media?parent=5104"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/categories?post=5104"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/tags?post=5104"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}