{"id":4143,"date":"2019-05-02T16:23:25","date_gmt":"2019-05-02T07:23:25","guid":{"rendered":"https:\/\/greentown.tokyo\/?p=4143"},"modified":"2019-05-02T16:29:33","modified_gmt":"2019-05-02T07:29:33","slug":"functiontype-pg","status":"publish","type":"post","link":"https:\/\/greentown.tokyo\/?p=4143","title":{"rendered":"\u95a2\u6570\u578b\u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0"},"content":{"rendered":"<p>\u5f15\u304d\u7d9a\u304dGW\u3072\u3068\u308a\u3082\u304f\u3082\u304f\u958b\u50ac\u4e2d\u3002<\/p>\n<p>\u5bb6\u4e8b\u3082\u305b\u305a\u3001\u7761\u7720\u6642\u9593\u3082\u524a\u308a\u3001\u3001\u3072\u305f\u3059\u3089\u30b4\u30ea\u30b4\u30ea\u30b3\u30fc\u30c9\u66f8\u3044\u3066\u307f\u305f\u308a\u3057\u3066\u3066\u3001\u96c6\u4e2d\u529b\u304c\u843d\u3061\u3066\u304d\u307e\u3057\u305f\u3002\u3002\uff08\u3061\u3087\u3063\u3068\u4ed6\u306e\u3053\u3068\u3082\u3084\u308a\u307e\u3057\u305f\u304c\uff09<\/p>\n<p><a href=\"https:\/\/oukayuka.booth.pm\/items\/1312652\">https:\/\/oukayuka.booth.pm\/items\/1312652<\/a><\/p>\n<p><a href=\"https:\/\/greentown.tokyo\/wp-content\/uploads\/2019\/05\/b58a45d3559cc75109305d27be6d5ea8.png\"><img decoding=\"async\" class=\"alignnone size-medium wp-image-4130\" src=\"https:\/\/greentown.tokyo\/wp-content\/uploads\/2019\/05\/b58a45d3559cc75109305d27be6d5ea8-300x300.png\" alt=\"\" width=\"300\" height=\"300\" srcset=\"https:\/\/greentown.tokyo\/wp-content\/uploads\/2019\/05\/b58a45d3559cc75109305d27be6d5ea8-300x300.png 300w, https:\/\/greentown.tokyo\/wp-content\/uploads\/2019\/05\/b58a45d3559cc75109305d27be6d5ea8-150x150.png 150w, https:\/\/greentown.tokyo\/wp-content\/uploads\/2019\/05\/b58a45d3559cc75109305d27be6d5ea8-768x766.png 768w, https:\/\/greentown.tokyo\/wp-content\/uploads\/2019\/05\/b58a45d3559cc75109305d27be6d5ea8-100x100.png 100w, https:\/\/greentown.tokyo\/wp-content\/uploads\/2019\/05\/b58a45d3559cc75109305d27be6d5ea8-400x400.png 400w, https:\/\/greentown.tokyo\/wp-content\/uploads\/2019\/05\/b58a45d3559cc75109305d27be6d5ea8-60x60.png 60w, https:\/\/greentown.tokyo\/wp-content\/uploads\/2019\/05\/b58a45d3559cc75109305d27be6d5ea8.png 1012w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>\u5f15\u304d\u7d9a\u304d\u3053\u3061\u3089\u3092\u3084\u3063\u3066\u3044\u307e\u3059\uff01\uff08GO\u3069\u3053\u308d\u304bReact\u307e\u3067\u3067\u304d\u308b\u306e\u304b\u301c\uff1f\uff1f\uff09<\/p>\n<h2>\u95a2\u6570\u578b\u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0<\/h2>\n<p>\u95a2\u6570\u578b\u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0\u306f\u3001\u307c\u3093\u3084\u308a\u3068\u60f3\u50cf\u3057\u3066\u3044\u305f\u306e\u3067\u3059\u304c\u3001\u601d\u3063\u3066\u3044\u305f\u306e\u3068\u306a\u3093\u304b\u9055\u3044\u307e\u3057\u305f\u3067\u3059\u30fb\u30fb\u3002<\/p>\n<h3>\u95a2\u6570\u578b\u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0\u3067\u5b9f\u73fe\u3055\u308c\u3066\u3044\u308b\u3053\u3068<\/h3>\n<ul>\n<li>\u7121\u540d\u95a2\u6570\u304c\u4f7f\u3048\u308b<\/li>\n<li>\u5909\u6570\u306b\u95a2\u6570\u3092\u4ee3\u5165\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u308b<\/li>\n<li>\u95a2\u6570\u306e\u5f15\u6570\u306b\u95a2\u6570\u304c\u6e21\u305b\u308b<\/li>\n<li>\u623b\u308a\u5024\u306b\u95a2\u6570\u3092\u8fd4\u3059\u3053\u3068\u304c\u3067\u304d\u308b\uff08\u9ad8\u968e\u95a2\u6570\uff09<\/li>\n<li>\u95a2\u6570\u306b\u7279\u5b9a\u306e\u5f15\u6570\u3092\u56fa\u5b9a\u3057\u305f\u65b0\u3057\u3044\u95a2\u6570\u3092\u4f5c\u308b\u3053\u3068\u304c\u3067\u304d\u308b\uff08\u90e8\u5206\u9069\u7528\uff09<\/li>\n<li>\u8907\u6570\u306e\u9ad8\u968e\u95a2\u6570\u3092\u5408\u6210\u3057\u3066\uff11\u3064\u306e\u95a2\u6570\u306b\u3067\u304d\u308b<\/li>\n<\/ul>\n<pre class=\"lang:js decode:true\">\/\/ \u7121\u540d\u95a2\u6570\u3092\r\nn =&gt; n * 2\r\n\/\/ \u5909\u6570\u306b\u4ee3\u5165\u3067\u304d\u308b\r\nconst double = n =&gt; n * 2<\/pre>\n<h3>Higher Order Fuction &#8211; \u9ad8\u968e\u95a2\u6570<\/h3>\n<ul>\n<li>\u5f15\u6570\u306b\u95a2\u6570\u3092\u3068\u308b\u3053\u3068\u304c\u3067\u304d\u308b<\/li>\n<li>\u623b\u308a\u5024\u306b\u95a2\u6570\u3092\u8fd4\u3059\u3053\u3068\u304c\u3067\u304d\u308b<\/li>\n<\/ul>\n<pre class=\"lang:js decode:true \">\/\/ \u5f15\u6570\u306b\u95a2\u6570\u3092\u6e21\u3059\r\nary.map(n =&gt; n * 2)\r\n\r\n\/\/ \u623b\u308a\u5024\u306b\u95a2\u6570\u3092\u8fd4\u3059\r\nconst hof=(ex,fn) =&gt; {\r\n     return n=&gt; fn(n + ex);\r\n};\r\nconst test = hof(1, n=&gt;n * 2);\r\nconsole.log(test(4));<\/pre>\n<pre class=\"theme:dark-terminal lang:default decode:true \">$ node higherorderfunction.js \r\n10<\/pre>\n<p>\u3080\u3080\u3045\u301c\u3002\u3088\u304f\u308f\u304b\u3089\u306c\u301c<br \/>\n(4+1) x 2 = 10 \u3089\u3057\u3043\u30fb\u30fb\u3080\u305a\u3043\u30a4\u30a3\u3002\u3002<br \/>\nHigher Order Component \uff08HOC\uff09\u3092\u7406\u89e3\u3059\u308b\u306e\u306b\u5fc5\u8981\u3089\u3057\u3043\u30fb\u30fb<br \/>\n\u6075\u6bd4\u5bff\u306eRreact\u3082\u304f\u3082\u304f\u884c\u3063\u3066\u805e\u3044\u3066\u307f\u3088\u3046\u304b\u3041\u30fb\u30fb<\/p>\n<h3>Closure\u3002\u30af\u30ed\u30fc\u30b8\u30e3\u30fc\u95a2\u6570<\/h3>\n<p>\u3053\u308c\u3082\u4ee5\u524d\u306b\u4f55\u5ea6\u3082Qiita\u307f\u305f\u308a\u3001\u30b0\u30b0\u3063\u305f\u308a\u3057\u305f\u3051\u3069\u3001\u3044\u307e\u3044\u3061\u308f\u304b\u3089\u3093\u306e\u3067\u3059\u3002<\/p>\n<ul>\n<li>Java\u306eClojure\u3067\u306f\u306a\u3044<\/li>\n<li>\u95a2\u6570\u9589\u5305<\/li>\n<\/ul>\n<h6>\u307e\u305a\u3001\u666e\u901a\u306b\u66f8\u3044\u3066\u307f\u308b<\/h6>\n<pre class=\"lang:js decode:true \">class Counter {\r\n     constructor(initialCount) {\r\n         this.c = initialCount;\r\n     }\r\n     increment() {\r\n         return this.c++;\r\n     }\r\n}\r\n \r\nconst counter = new Counter(1);\r\nconsole.log(counter.increment(), counter.increment(), counter.increment());<\/pre>\n<pre class=\"theme:dark-terminal lang:default decode:true \">$ node closure.js \r\n1 2 3<\/pre>\n<h6>\u30af\u30ed\u30fc\u30b8\u30e3\u30fc\u3092\u4f7f\u3046<\/h6>\n<pre class=\"lang:js decode:true \">const counterMaker = (initialCount) =&gt; {\r\n     let c = initialCount; \/\/ Why? \u30af\u30ea\u30a2\u3055\u308c\u306a\u3044\r\n     const increment = () =&gt; c++;\r\n     return increment; \/\/ \u95a2\u6570\u300cincrement = () =&gt; c++\u300d\u3092\u8fd4\u3057\u3066\u3044\u308b\r\n};\r\nconst count = counterMaker(1);\r\nconsole.log(count(), count(), count());<\/pre>\n<pre class=\"theme:dark-terminal lang:default decode:true \">$ node closure.js \r\n1 2 3<\/pre>\n<p>count()\u306e\u623b\u308a\u304c\u3001\u5185\u90e8\u95a2\u6570\u306eincrement\uff08increment = () =&gt; c++;\uff09countMarker\u5185\u90e8\u3067\u5b9f\u884c\u3055\u308c\u308b\u304b\u3089\u3001c\u306e\u5024\u304c\u30ea\u30bb\u30c3\u30c8\u3055\u308c\u305a\u306b\u84c4\u7a4d\u3055\u308c\u3066\u3044\u304f<br \/>\n<span style=\"color: #ff00ff;\"><strong><span style=\"font-size: 150%;\">\u305d\u30fc\u3086\u30fc\u3082\u3093\uff01<\/span><\/strong><\/span><br \/>\nReact\u306e\u30c6\u30a4\u3067\u3044\u3046\u3068<br \/>\n\u95a2\u6570\u30b3\u30f3\u30dd\u30fc\u30cd\u30f3\u30c8\u3092\u5b9f\u88c5\u3059\u308b\u3068\u304d\u3001\u5916\u90e8\u30b9\u30b3\u30fc\u30d7\u306e\u5909\u6570\u3092\u53c2\u7167\u3059\u308b\u95a2\u6570\u3092\u5b9a\u7fa9\u3059\u308b\u3053\u3068\u304c\u3042\u308b\u3001\u305d\u308c\u304c\u30af\u30ed\u30fc\u30b8\u30e3\u30fc\u306b\u3042\u305f\u308b\u30fb\u30fb\u30fb\u3089\u3057\u3044\u3002<br \/>\n\u3080\u3080\u3045\u30fb\u30fb<\/p>\n<h3>\u30b8\u30a7\u30cd\u30ec\u30fc\u30bf\u95a2\u6570<\/h3>\n<ul>\n<li>\u5024\u3092\u4fdd\u6301\u3057\u3064\u3064\u7e70\u308a\u8fd4\u3057\u51e6\u7406\u3084\u9010\u6b21\u51e6\u7406\u3092\u884c\u3046\u305f\u3081\u306e\u95a2\u6570<\/li>\n<\/ul>\n<pre class=\"lang:js decode:true\">function* rangeGenerator(end, start = 0) {\r\n    let n = 0;\r\n    for (let i=start; i&lt;end; i++) {\r\n      n+=1;\r\n      yield i;\r\n     }\r\n}\r\n  \r\nconst gen = rangeGenerator(3);\r\nconsole.log(gen.next());\r\nconsole.log(gen.next());\r\nconsole.log(gen.next());\r\nconsole.log(gen.next());\r\nconsole.log(gen.next());<\/pre>\n<pre class=\"theme:dark-terminal lang:default decode:true \">$ node generator.js \r\n{ value: 0, done: false }\r\n{ value: 1, done: false }\r\n{ value: 2, done: false }\r\n{ value: undefined, done: true }\r\n{ value: undefined, done: true }<\/pre>\n<p>\u3063\u3066\u306e\u304c\u3042\u308b\u3002\u8a73\u3057\u304f\u306f\u672c\u53c2\u8003\u3002\u4f55\u3068\u306a\u304f\u899a\u3048\u3066\u304a\u304f\u3002<\/p>\n<p>\u5fc5\u8981\u306b\u306a\u3063\u305f\u3089\u898b\u8fd4\u305d\u3046\u30fb\u30fb\u30fb<\/p>\n<h3>\u30ab\u30ea\u30fc\u5316<\/h3>\n<p>\u3060\u3093\u3060\u3093\u30fb\u30fb\u3064\u3044\u3066\u884c\u3051\u306a\u304f\u306a\u3063\u3066\u304d\u305f\u3041\u301c\uff08\u6ce3<\/p>\n<ul>\n<li>\u8907\u6570\u306e\u5f15\u6570\u3092\u3068\u308b\u95a2\u6570\u3092\u3001\u3072\u3068\u3064\u3060\u3051\u5f15\u6570\u3092\u3068\u308b\u95a2\u6570\u306b\u5206\u5272\u3057\u3066\u30cd\u30b9\u30c8\u3055\u305b\u308b\u3053\u3068<\/li>\n<\/ul>\n<p>\u4f55\u306e\u305f\u3081\u306b\u305d\u3093\u306a\u3053\u3068\u3059\u308b\u306d\u3093\u3002\u3002<\/p>\n<p>\u7406\u89e3\u306f\u8ffd\u3044\u8ffd\u3044\u3068\u3057\u3066\u3001\u3068\u308a\u3042\u3048\u305a\u52d5\u4f5c\u78ba\u8a8d\u3057\u3066\u304a\u304f\u3002<\/p>\n<pre class=\"lang:js decode:true \">const multi = (n,m) =&gt; n * m;\r\nconsole.log(multi(2,4));\r\n \r\nconst curriedMulti = n =&gt; {\r\n     console.log(n);\r\n     return m =&gt; n * m;\r\n}\r\nconsole.log(curriedMulti(2)(4));\r\n \r\nconst simpleCurriedMulti = n =&gt; m =&gt; n * m;\r\nconsole.log(simpleCurriedMulti(2)(4));<\/pre>\n<pre class=\"theme:dark-terminal lang:default decode:true \">$ node curring.js \r\n8\r\n2\r\n8\r\n8<\/pre>\n<h6>\u30ab\u30ea\u30fc\u5316\u90e8\u5206\u9069\u7528<\/h6>\n<p>\u7528\u9014\u304c\u60f3\u50cf\u3064\u304b\u306a\u3044\u3093\u3060\u3051\u3069\u3001\u52d5\u304b\u3057\u3066\u304a\u304f<\/p>\n<pre class=\"lang:default decode:true \">const multi = n =&gt; m =&gt; n * m;\r\nconsole.log(multi(3)(5));\r\n \r\nconst triple = multi(3);\r\nconsole.log(triple(5));<\/pre>\n<pre class=\"theme:dark-terminal lang:default decode:true \">$ node curring2.js \r\n15\r\n15<\/pre>\n<p>\u4f55\u3068\u306a\u30fc\u304f\u3001\u4f55\u306a\u30fc\u306a\u3041\u3041\u3042\u30fc\u304f\u30fb\u30fb\u3053\u3093\u306a\u306e\u304c\u3042\u308b\u306e\u306d\u301c\u306a\u611f\u3058\u3067\u3001\u982d\u306e\u9685\u306b\u7f6e\u3044\u3066\u304a\u304f\u30fb\u30fb\u3002<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5f15\u304d\u7d9a\u304dGW\u3072\u3068\u308a\u3082\u304f\u3082\u304f\u958b\u50ac\u4e2d\u3002 \u5bb6\u4e8b\u3082\u305b\u305a\u3001\u7761\u7720\u6642\u9593\u3082\u524a\u308a\u3001\u3001\u3072\u305f\u3059\u3089\u30b4\u30ea\u30b4\u30ea\u30b3\u30fc\u30c9\u66f8\u3044\u3066\u307f\u305f\u308a\u3057\u3066\u3066\u3001\u96c6\u4e2d\u529b\u304c\u843d\u3061\u3066\u304d\u307e\u3057\u305f\u3002\u3002\uff08\u3061\u3087\u3063\u3068\u4ed6\u306e\u3053\u3068\u3082\u3084\u308a\u307e\u3057\u305f\u304c\uff09 https:\/\/oukayuk &#8230; <\/p>\n","protected":false},"author":1,"featured_media":4130,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[79,97],"tags":[],"class_list":["post-4143","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-note","category-react"],"_links":{"self":[{"href":"https:\/\/greentown.tokyo\/index.php?rest_route=\/wp\/v2\/posts\/4143"}],"collection":[{"href":"https:\/\/greentown.tokyo\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/greentown.tokyo\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/greentown.tokyo\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/greentown.tokyo\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=4143"}],"version-history":[{"count":6,"href":"https:\/\/greentown.tokyo\/index.php?rest_route=\/wp\/v2\/posts\/4143\/revisions"}],"predecessor-version":[{"id":4149,"href":"https:\/\/greentown.tokyo\/index.php?rest_route=\/wp\/v2\/posts\/4143\/revisions\/4149"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/greentown.tokyo\/index.php?rest_route=\/wp\/v2\/media\/4130"}],"wp:attachment":[{"href":"https:\/\/greentown.tokyo\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=4143"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/greentown.tokyo\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=4143"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/greentown.tokyo\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=4143"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}