{"id":5556,"date":"2018-07-07T23:32:09","date_gmt":"2018-07-07T14:32:09","guid":{"rendered":"http:\/\/www.code-magagine.com\/?p=5556"},"modified":"2023-05-27T21:00:50","modified_gmt":"2023-05-27T12:00:50","slug":"%e3%80%90javascript%e3%80%91%e3%80%8c%e3%82%af%e3%83%ad%e3%83%bc%e3%82%b8%e3%83%a3%e3%80%8d%e3%81%ab%e3%81%a4%e3%81%84%e3%81%a6","status":"publish","type":"post","link":"http:\/\/www.code-magagine.com\/?p=5556","title":{"rendered":"\u3010JavaScript\u3011\u300c\u30af\u30ed\u30fc\u30b8\u30e3\u300d\u306b\u3064\u3044\u3066"},"content":{"rendered":"<h2>\u30af\u30ed\u30fc\u30b8\u30e3\u3092\u7406\u89e3\u3059\u308b\u305f\u3081\u306e\u30dd\u30a4\u30f3\u30c8<\/h2>\n<h3>JavaScript\u306f\u95a2\u6570\u306e\u4e2d\u306b\u95a2\u6570\u3092\u5b9a\u7fa9\u3067\u304d\u308b\u3002<\/h3>\n<p>JavaScript\u7279\u6709\u306e\u69cb\u6587\u306b\u306a\u308a\u307e\u3059\u3002\uff08Java\u3084C\u8a00\u8a9e\u306a\u3069\u3067\u306f\u3067\u304d\u306a\u3044\u3002\uff09<\/p>\n<pre class=\"lang:default decode:true \">function parentFunc() {\r\n  console.log('\u89aa\u3067\u3059\u3002');\r\n  function childrenFunc() {\r\n    console.log('\u5b50\u4f9b\u3067\u3059\u3002');\r\n  }\r\n}\r\n\r\nparentFunc();<\/pre>\n<h3>JavaScript\u306e\u95a2\u6570\u306f\u5909\u6570\u306e\u4e2d\u306b\u5165\u308c\u3066\u5909\u6570\u3068\u3057\u3066\u6301\u3061\u904b\u3079\u308b\u3002<\/h3>\n<p>\u3053\u306e\u6027\u8cea\u3082\u3067\u304d\u306a\u3044\u8a00\u8a9e\u306f\u3044\u3063\u3071\u3044\u3042\u308a\u307e\u3059\u3002<\/p>\n<pre class=\"lang:default decode:true \">function parentFunc() {\r\n  console.log('\u89aa\u3067\u3059\u3002');\r\n  function childrenFunc() {\r\n    console.log('\u5b50\u4f9b\u3067\u3059\u3002');\r\n  }\r\n  return childrenFunc;\r\n}\r\n\r\nfunction reserveFunc(a) {\r\n  a();\r\n}\r\n\r\nconst child = parentFunc(); \/\/ \u89aa\u3067\u3059\u3002\r\nchild(); \/\/ \u5b50\u4f9b\u3067\u3059\u3002\r\n\r\nreserveFunc(child); \/\/ \u5b50\u4f9b\u3067\u3059\u3002\r\n<\/pre>\n<h3>JavaScript\u306e\u95a2\u6570\u306f\u89aa\u306e\u5909\u6570\u306e\u5024\u3092\u4f7f\u3048\u308b\u3002<\/h3>\n<p>JavaScript\u306e\u95a2\u6570\u306f\u5225\u306e\u95a2\u6570\u306e\u5909\u6570\u3092\u4f7f\u3046\u3053\u3068\u304c\u3067\u304d\u307e\u305b\u3093\u3002\u3057\u304b\u3057\u3001\u95a2\u6570\u304c\u89aa\u5b50\u95a2\u4fc2\u306b\u3042\u308b\u5834\u5408\u306f\u89aa\u306e\u95a2\u6570\u306e\u5909\u6570\u3092\u4f7f\u3048\u307e\u3059\u3002\uff08\u306a\u304a\u3001\u89aa\u3060\u3051\u3067\u306a\u304f\u7956\u7236\u6bcd\u306a\u3069\u7956\u5148\u8981\u7d20\u306f\u5168\u3066\u53c2\u7167\u3067\u304d\u307e\u3059\u3002\uff1a\u30b9\u30b3\u30fc\u30d7\u30c1\u30a7\u30a4\u30f3\uff09<\/p>\n<pre class=\"lang:default decode:true \">function parentFunc() {\r\n  const oyaValue = '\u89aa';\r\n  console.log('\u89aa\u3067\u3059\u3002');\r\n  function childrenFunc() {\r\n    console.log(`${oyaValue}\u306e\u5b50\u4f9b\u3067\u3059\u3002`);\r\n  }\r\n  return childrenFunc;\r\n}<\/pre>\n<h3>JavaScript\u306e\u95a2\u6570\u306e\u300c\u89aa\u300d\u306f\u300c\u751f\u307f\u306e\u89aa\u300d\u306e\u3053\u3068\u3002<\/h3>\n<p>\u5b9f\u884c\u3055\u308c\u305f\u30bf\u30a4\u30df\u30f3\u30b0\u3067\u306f\u306a\u304f\u3001\u5b9a\u7fa9\u3055\u308c\u305f\u5834\u6240\u306e\u89aa\u3092\u89aa\u306e\u95a2\u6570\u3068\u3057\u307e\u3059\u3002\u3053\u308c\u3092<span style=\"color: #ff0000;\"><strong>\u300c\u30ec\u30ad\u30b7\u30ab\u30eb\u30b9\u30b3\u30fc\u30d7\u300d<\/strong><\/span>\u3068\u547c\u3073\u307e\u3059\u3002\uff08\u306a\u304a\u3001\u5b9f\u884c\u3055\u308c\u305f\u30bf\u30a4\u30df\u30f3\u30b0\u306e\u95a2\u6570\u3092\u89aa\u3068\u3059\u308b\u8003\u3048\u65b9\u3092\u300c\u30c0\u30a4\u30ca\u30df\u30c3\u30af\u30b9\u30b3\u30fc\u30d7\u300d\u3068\u547c\u3073\u307e\u3059\u3002JavaScript\u306f\u30c0\u30a4\u30ca\u30df\u30c3\u30af\u30b9\u30b3\u30fc\u30d7\u3067\u306f\u306a\u3044\u3067\u3059\u304c\u3002\uff09<\/p>\n<pre class=\"lang:default decode:true \">function parentFunc() {\r\n  const oyaValue = '\u89aa';\r\n  console.log('\u89aa\u3067\u3059\u3002');\r\n  function childrenFunc() {\r\n    console.log(`${oyaValue}\u306e\u5b50\u4f9b\u3067\u3059\u3002`);\r\n  }\r\n  return childrenFunc;\r\n}\r\n\r\nfunction reserveFunc(a) {\r\n  const betujin = '\u5225\u4eba';\r\n  a(); \/\/ betujin\u3068\u3044\u3046\u5909\u6570\u306b\u306f\u30a2\u30af\u30bb\u30b9\u3067\u304d\u306a\u3044\u3002\r\n}\r\n\r\nconst child = parentFunc(); \/\/ \u89aa\u3067\u3059\u3002\r\nchild(); \/\/ \u5b50\u4f9b\u3067\u3059\u3002\r\n\r\nreserveFunc(child); \/\/ \u5b50\u4f9b\u3067\u3059\u3002\r\n<\/pre>\n<h2>\u300c\u30af\u30ed\u30fc\u30b8\u30e3\u300d\u3068\u306f\uff1f<\/h2>\n<p>\u4e00\u8a00\u3067\u8a00\u3048\u3070\u3001<span style=\"color: #ff0000;\"><strong>\u300c\u89aa\u306e\u30ed\u30fc\u30ab\u30eb\u5909\u6570\u3092\u53c2\u7167\u3057\u3066\u3044\u308b\u95a2\u6570\u5185\u95a2\u6570\u306e\u3053\u3068\u300d<\/strong><\/span>\u3067\u3001\u4e00\u6642\u8a18\u61b6\u9818\u57df\u3092\u63d0\u4f9b\u3057\u7d9a\u3051\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n<p>\u901a\u5e38\u306f\u3001\u30ed\u30fc\u30ab\u30eb\u5909\u6570\u306f\u3001\u95a2\u6570\u304c\u547c\u3070\u308c\u7d42\u308f\u3063\u305f\u3089\u5185\u5bb9\u304c\u30af\u30ea\u30a2\u3055\u308c\u307e\u3059\u3002<\/p>\n<p>\u3057\u304b\u3057\u3001<span style=\"color: #ff0000;\"><strong>\u95a2\u6570\u5185\u306e\u95a2\u6570\u304c\u30ed\u30fc\u30ab\u30eb\u5909\u6570\u3092\u53c2\u7167\u3057\u3066\u3044\u308b\u5834\u5408\u306f\u3001\u95a2\u6570\u7d42\u4e86\u5f8c\u3082\u3001\u30ed\u30fc\u30ab\u30eb\u5909\u6570\u306e\u5024\u306f\u4fdd\u6301\u3055\u308c\u7d9a\u3051\u307e\u3059\u3002<\/strong><\/span><\/p>\n<h2>\u7528\u9014<\/h2>\n<h3>\u7ba1\u7406\u3057\u3084\u3059\u3044\u5909\u6570\u3092\u4f5c\u308b\u305f\u3081<\/h3>\n<p>\u30b0\u30ed\u30fc\u30d0\u30eb\u5909\u6570\u3060\u3068\u5024\u304c\u3061\u3083\u3093\u3068\u6b63\u5e38\u304b\u5e38\u306b\u6c17\u3092\u4f7f\u308f\u306a\u3044\u3068\u30c0\u30e1\u3067\u3059\u304c\u3001\u30af\u30ed\u30fc\u30b8\u30e3\u30fc\u306e\u5909\u6570\u306a\u3089\u6c17\u3092\u4f7f\u3046\u5fc5\u8981\u304c\u306a\u3044\u3067\u3059\u3002\uff08\u5916\u5074\u304b\u3089\u306f\u7d76\u5bfe\u306b\u30a2\u30af\u30bb\u30b9\u304c\u3055\u308c\u306a\u3044\u30d7\u30e9\u30a4\u30d9\u30fc\u30c8\u5909\u6570\u306b\u306a\u308b\u3002\uff09<\/p>\n<pre class=\"lang:default decode:true \">let generatePerson = () =&gt; {\r\n  let age = 0;\r\n  return {\r\n    getAge: () =&gt; age,\r\n    incrementAge: () =&gt; {\r\n      age += 1;\r\n      console.log(\"age\", age);\r\n    },\r\n  };\r\n};\r\n\r\nconst person = generatePerson();\r\nperson.incrementAge();\r\nperson.incrementAge();\r\nconsole.log(person.getAge());\r\n<\/pre>\n<p>generatePerson\u306eincrementAge\u3067\u305d\u306e\u307e\u307e\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3092\u8fd4\u3057\u3066\u3057\u307e\u3046\u3068\u5916\u5074\u304b\u3089\u64cd\u4f5c\u3067\u304d\u3066\u3057\u307e\u3044\u307e\u3059\u304c\u3001\u95a2\u6570\u3092\u8fd4\u305b\u3070\u5916\u5074\u304b\u3089\u306f\u81ea\u7531\u306b\u5024\u3092\u5909\u66f4\u3067\u304d\u307e\u305b\u3093\u3002<\/p>\n<p>getAge\u3082\u305d\u306e\u307e\u307eage\u3092\u8fd4\u3059\u306e\u3067\u306f\u306a\u304f\u95a2\u6570\u3092\u8fd4\u3057\u3066\u3044\u308b\u306e\u304c\u7279\u5fb4\u3067\u3059\u3002<\/p>\n<h3>\u30b3\u30fc\u30eb\u30d0\u30c3\u30af\u95a2\u6570\u3092\u30ab\u30b9\u30bf\u30de\u30a4\u30ba\u3057\u3066\u30b3\u30fc\u30c9\u3092\u30b9\u30c3\u30ad\u30ea\u3055\u305b\u308c\u308b\u3002<\/h3>\n<p>\u30b3\u30fc\u30eb\u30d0\u30c3\u30af\u95a2\u6570\u306b\u3088\u3063\u3066\u306f\u6c7a\u3081\u3089\u308c\u305f\u30b7\u30b0\u30cd\u30c1\u30e3\u3057\u304b\u53d7\u3051\u4ed8\u3051\u3066\u304f\u308c\u306a\u3044\u3002\u3057\u304b\u3057\u3001\u30af\u30ed\u30fc\u30b8\u30e3\u3092\u4f7f\u3063\u3066\u95a2\u6570\u3092\u518d\u5b9a\u7fa9\u3057\u3066\u3042\u3052\u308b\u3053\u3068\u306b\u3088\u3063\u3066\u5225\u9014\u6761\u4ef6\u5206\u5c90\u3057\u3066\u5b9a\u7fa9\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u308b\u3002<\/p>\n<p>\u5229\u70b9\u3068\u3057\u3066\u306f\u3001<span style=\"color: #ff0000;\"><strong>\u30b3\u30fc\u30eb\u30d0\u30c3\u30af\u5730\u7344\u3092\u8131\u51fa\u3055\u305b\u3066\u30b3\u30fc\u30c9\u3092\u30b9\u30c3\u30ad\u30ea\u8a18\u8ff0\u3059\u308b\u305f\u3081\u306e\u624b\u6bb5<\/strong><\/span>\u3068\u3057\u3066\u4f7f\u308f\u308c\u308b\u3002\uff08\u4eca\u307e\u3067\u306f\u5165\u308c\u5b50\u306b\u3057\u307e\u304f\u3063\u3066\u3044\u305f\u306e\u304c\u30af\u30ed\u30fc\u30b8\u30e3\u3092\u4f7f\u3048\u3070\u5f15\u6570\u3068\u3057\u3066\u5fc5\u8981\u306a\u3082\u306e\u3092\u6e21\u3057\u3066\u3042\u3052\u308c\u3070\u3001\u89aa\u306e\u5909\u6570\u3092\u4f7f\u3046\u3053\u3068\u304c\u3067\u304d\u308b\u306e\u3067\u5916\u3060\u3057\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u308b\u305f\u3081\u3002\uff09<\/p>\n<p>\u305f\u3060\u3001\u4eca\u306fPromise\u3084async\u3001await\u306a\u3069\u306e\u69cb\u6587\u304c\u3042\u308b\u305f\u3081\u305d\u3061\u3089\u3067\u3082\u4ee3\u66ff\u306f\u53ef\u80fd\u3002<\/p>\n<h2>\u4f8b<\/h2>\n<h3>\u5b9a\u7fa9<\/h3>\n<p>\u4ee5\u4e0b\u306e\u4f8b\u3067\u8a00\u3048\u3070\u3001\u300cinnerFunc\u300d\u304c\u30af\u30ed\u30fc\u30b8\u30e3\u306b\u306a\u308a\u307e\u3059\u3002\uff08\u901a\u5e38\u306f\u7121\u540d\u95a2\u6570\u306b\u3059\u308b\u3053\u3068\u304c\u591a\u3044\u3067\u3059\u3002\uff09<\/p>\n<pre class=\"lang:default decode:true\">function outerFunc() {\r\n\r\n    const a = 1;\r\n\r\n    function innerFunc() {\r\n        a = a + 1\r\n    }\r\n\r\n    return innerFunc();\r\n}<\/pre>\n<h3>\u547c\u3073\u51fa\u3057<\/h3>\n<pre class=\"lang:default decode:true \">var closure = outerFunc()\r\n\r\nclosure(); \/\/ 1\r\nclosure(); \/\/ 2\r\nclosure(); \/\/ 3<\/pre>\n","protected":false},"excerpt":{"rendered":"\u30af\u30ed\u30fc\u30b8\u30e3\u3092\u7406\u89e3\u3059\u308b\u305f\u3081\u306e\u30dd\u30a4\u30f3\u30c8 JavaScript\u306f\u95a2\u6570\u306e\u4e2d\u306b\u95a2\u6570\u3092\u5b9a\u7fa9\u3067\u304d\u308b\u3002 JavaScript\u7279\u6709\u306e\u69cb\u6587\u306b\u306a\u308a\u307e\u3059\u3002\uff08Java\u3084C\u8a00\u8a9e\u306a\u3069\u3067\u306f\u3067\u304d\u306a\u3044\u3002\uff09 function parentFunc() { c [&hellip;]","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[16],"tags":[],"_links":{"self":[{"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=\/wp\/v2\/posts\/5556"}],"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=5556"}],"version-history":[{"count":15,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=\/wp\/v2\/posts\/5556\/revisions"}],"predecessor-version":[{"id":20298,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=\/wp\/v2\/posts\/5556\/revisions\/20298"}],"wp:attachment":[{"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=5556"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=5556"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=5556"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}