{"id":17919,"date":"2022-09-24T10:39:47","date_gmt":"2022-09-24T01:39:47","guid":{"rendered":"http:\/\/www.code-magagine.com\/?p=17919"},"modified":"2023-05-27T23:24:07","modified_gmt":"2023-05-27T14:24:07","slug":"%e3%80%90typescript%e3%80%91%e3%80%8c%e3%82%b7%e3%83%b3%e3%82%b0%e3%83%ab%e3%83%88%e3%83%b3%e3%82%af%e3%83%a9%e3%82%b9%e3%80%8d%e3%82%92%e4%bd%9c%e3%82%8b%e3%81%ab%e3%81%af","status":"publish","type":"post","link":"http:\/\/www.code-magagine.com\/?p=17919","title":{"rendered":"\u3010TypeScript\u3011\u300c\u30b7\u30f3\u30b0\u30eb\u30c8\u30f3\u30af\u30e9\u30b9\u300d\u3092\u4f5c\u308b\u306b\u306f"},"content":{"rendered":"<h2>constructor\u95a2\u6570\u306bprivate\u4fee\u98fe\u5b50\u3092\u3064\u3051\u308b<\/h2>\n<p>constructor\u95a2\u6570\u306bprivate\u4fee\u98fe\u5b50\u3092\u3064\u3051\u307e\u3059\u3002<\/p>\n<pre class=\"lang:default decode:true\">class Person {\r\n  name: string;\r\n  private constructor() {\r\n    this.name = \"\u7530\u4e2d\";\r\n  }\r\n}<\/pre>\n<p>\u305d\u3046\u3059\u308b\u3068\u5916\u90e8\u304b\u3089new\u3067\u304d\u306a\u304f\u306a\u308a\u307e\u3059\u3002<\/p>\n<pre class=\"lang:default decode:true \">const peson = new Person(); \/\/\u30a8\u30e9\u30fc\u306b\u306a\u308b\u3002<\/pre>\n<p>class\u5185\u90e8\u306e\u30e1\u30bd\u30c3\u30c9\u304b\u3089\u306a\u3089\u30a2\u30af\u30bb\u30b9\u3067\u304d\u308b\u306e\u3067\u4ee5\u4e0b\u306e\u3088\u3046\u306bgetInstance\u3068\u3044\u3046static\u30e1\u30bd\u30c3\u30c9\u3092\u4f5c\u3063\u3066\u305d\u308c\u3092\u547c\u3076\u3088\u3046\u306b\u3057\u307e\u3059\u3002<\/p>\n<pre class=\"lang:default decode:true\">class Person {\r\n  private static instance: Person;\r\n\r\n  name: string;\r\n  private constructor() {\r\n    this.name = \"\u7530\u4e2d\";\r\n  }\r\n\r\n  static getInstance() {\r\n    if (Person.instance) return Person.instance;\r\n    Person.instance = new Person();\r\n    return Person.instance;\r\n  }\r\n}\r\n\r\nconst peson = Person.getInstance();<\/pre>\n<h2>\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3092export\u3059\u308b\u3002<\/h2>\n<p>\u53e4\u3044\u30d6\u30e9\u30a6\u30b6\u3060\u3068\u52d5\u304b\u306a\u3044\u5834\u5408\u304c\u3042\u308b\u306e\u3067\u3001\u305d\u306e\u5834\u5408\u306f\u30b7\u30f3\u30b0\u30eb\u30c8\u30f3\u306f\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u3082\u8a18\u8ff0\u3067\u304d\u307e\u3059\u3002<\/p>\n<pre class=\"lang:default decode:true\">class Person {\r\n  private static instance: Person;\r\n\r\n  name: string;\r\n  private constructor() {\r\n    this.name = \"\u7530\u4e2d\";\r\n  }\r\n\r\n  static getInstance() {\r\n    if (Person.instance) return Person.instance;\r\n    Person.instance = new Person();\r\n    return Person.instance;\r\n  }\r\n}\r\n\r\nexport default new Person();<\/pre>\n<p>\u3053\u308c\u3092\u5225\u30d5\u30a1\u30a4\u30eb\u3067import\u3059\u308b\u3053\u3068\u306b\u3088\u3063\u3066\u4e00\u3064\u306e\u30a4\u30f3\u30b9\u30bf\u30f3\u30b9\u304c\u5171\u6709\u3055\u308c\u307e\u3059\u3002<\/p>\n<p>\u3053\u3061\u3089\u306e\u65b9\u304c\u7c21\u6f54\u306b\u66f8\u3051\u307e\u3059\u306d\u3002<\/p>\n<p>\u305f\u3060\u3001\u901a\u5e38\u306e\u30b7\u30f3\u30b0\u30eb\u30c8\u30f3\u3068\u306f\u8a18\u8ff0\u65b9\u6cd5\u304c\u7570\u306a\u308b\u306e\u3067\u30b7\u30f3\u30b0\u30eb\u30c8\u30f3\u30af\u30e9\u30b9\u3060\u3068\u3044\u307e\u3044\u3061\u308f\u304b\u308a\u3065\u3089\u3044\u3053\u3068\u304c\u6b20\u70b9\u3068\u8a00\u3048\u308b\u304b\u3082\u3057\u308c\u307e\u305b\u3093\u3002<\/p>\n<p>\u30af\u30e9\u30b9\u540d\u3067\u30b7\u30f3\u30b0\u30eb\u30c8\u30f3\u3068\u3044\u3046\u3053\u3068\u304c\u308f\u304b\u308b\u3088\u3046\u306b\u3059\u308b\u304b\u3001\u30b3\u30e1\u30f3\u30c8\u3067\u88dc\u8db3\u3059\u308b\u5fc5\u8981\u304c\u3042\u308b\u304b\u3082\u3057\u308c\u307e\u305b\u3093\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"constructor\u95a2\u6570\u306bprivate\u4fee\u98fe\u5b50\u3092\u3064\u3051\u308b constructor\u95a2\u6570\u306bprivate\u4fee\u98fe\u5b50\u3092\u3064\u3051\u307e\u3059\u3002 class Person { name: string; private constructor() [&hellip;]","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[101],"tags":[],"_links":{"self":[{"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=\/wp\/v2\/posts\/17919"}],"collection":[{"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=17919"}],"version-history":[{"count":5,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=\/wp\/v2\/posts\/17919\/revisions"}],"predecessor-version":[{"id":20597,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=\/wp\/v2\/posts\/17919\/revisions\/20597"}],"wp:attachment":[{"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=17919"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=17919"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=17919"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}