{"id":107669,"date":"2021-03-31T20:35:20","date_gmt":"2021-03-31T11:35:20","guid":{"rendered":"http:\/\/www.key-p.com\/blog\/staff\/?p=107669"},"modified":"2021-03-31T20:36:24","modified_gmt":"2021-03-31T11:36:24","slug":"proxy%e3%82%aa%e3%83%96%e3%82%b8%e3%82%a7%e3%82%af%e3%83%88%e3%82%92%e4%bd%bf%e3%81%a3%e3%81%a6%e3%81%bf%e3%82%88%e3%81%86","status":"publish","type":"post","link":"https:\/\/www.key-p.com\/blog\/staff\/archives\/107669","title":{"rendered":"Proxy\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3092\u4f7f\u3063\u3066\u307f\u3088\u3046"},"content":{"rendered":"<p>\n\u6e9d\u7551\u3067\u3059\u3002<br \/>\n\u4eca\u65e5\u306fProxy\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306b\u3064\u3044\u3066\u3002<br \/>\n<br \/>\nJavaScript\u66f8\u3044\u3066\u3044\u3066\u3001\u3068\u304f\u306b\u30c6\u30f3\u30d7\u30ec\u30fc\u30c8\u3068\u304b\u4f7f\u308f\u305a\u3001HTML\u7d44\u307f\u7acb\u3066\u3066\u5dee\u3057\u66ff\u3048\u308b\u307f\u305f\u3044\u306a\u30b1\u30fc\u30b9\u3042\u308a\u307e\u305b\u3093\u304b\uff1f\uff1f<br \/>\n\u305d\u306e\u3068\u304d\u3001\u3068\u304f\u306b\u30c7\u30fc\u30bf\u3092\u7cbe\u67fb\u305b\u305a\u305d\u306e\u307e\u307e\u7d44\u307f\u7acb\u3066\u308b\u3068\u3001\u601d\u308f\u306c\u3068\u3053\u308d\u3067\u8868\u793a\u304cnull\u306b\u306a\u3063\u305f\u308a\u30fb\u30fb\u30fb\u3002<br \/>\n\u305d\u306e\u5ea6\u306b\u6761\u4ef6\u3064\u3051\u3066\u7a7a\u6587\u5b57\u306b\u3057\u3066\u3042\u3052\u305f\u308a\u3001\u7d50\u69cb\u9762\u5012\u306a\u3053\u3068\u304c\u3042\u308a\u307e\u3059\u3002<br \/>\n(API\u3067\u7d71\u4e00\u3057\u3066\u304f\u308c\u3068\u3044\u3046\u8a71\u3067\u3082\u3042\u308a\u307e\u3059\u304c)<br \/>\n<br \/>\n\u305d\u3093\u306a\u72b6\u6cc1\u3001Proxy\u4f7f\u3046\u3068\u7d50\u69cb\u697d\u306b\u306a\u308a\u307e\u3059\u3088\u3068\u3044\u3046\u304a\u8a71\u3067\u3059\u3002<br \/>\n<br \/>\n<h4>Proxy\u30aa\u30d6\u30b8\u30a7\u30af\u30c8<\/h4>\n\u4f7f\u3044\u65b9\u3002<br \/>\n<pre class=\"lang:js decode:true \" >const proxy = new Proxy(target, handler)<\/pre>\ntarget\u3067\u6307\u5b9a\u3057\u305f\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306bhandler\u3067\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306b\u5bfe\u3057\u3066\u3069\u3046\u3059\u308b\u306e\u304b\u3001\u30c8\u30e9\u30c3\u30d7\u3068\u3044\u3046\u30e1\u30bd\u30c3\u30c9\u3092\u5b9a\u7fa9\u3057\u3066\u3044\u304d\u307e\u3059\u3002<br \/>\n<br \/>\n<pre class=\"lang:js decode:true \" >const data = {\n  name: '\u25cb\u25cb\u5e02'\n  temp: 20\n}\n\nconst proxy = new Proxy(data, {\n  get(target, name) {\n    if (name === 'temp') {\n      return target[name] + '\u5ea6'\n    }\n    return target[name]\n  }\n})\n\nconsole.log(proxy.temp) \/\/ 20\u5ea6<\/pre>\n\u3053\u306e\u4f8b\u3060\u3068\u3001temp\u306e\u6642\u306f\u5f8c\u308d\u306b\u300c\u5ea6\u300d\u3092\u4ed8\u3051\u3066\u3044\u307e\u3059\u3002<br \/>\n\u3053\u306e\u3088\u3046\u306b\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306b\u30a2\u30af\u30bb\u30b9\u3055\u308c\u305f\u3068\u304d\u306e\u51e6\u7406\u3092\u66f8\u3044\u3066\u304a\u3051\u307e\u3059\u3002<br \/>\n<br \/>\n<h4>\u4f7f\u3044\u6240<\/h4>\n\u30bb\u30f3\u30b5\u30fc\u304b\u3089\u53d6\u5f97\u3057\u305f\u5024\u3067\u3001\u4f55\u3089\u304b\u306e\u4e8b\u60c5\u3067\u30a8\u30e9\u30fc\u5024\u304c\u5165\u3063\u3066\u3044\u308b\u3053\u3068\u304c\u3042\u308b\u30fb\u30fb\u30fb\u3088\u3046\u306a\u72b6\u6cc1\u3092\u8003\u3048\u307e\u3059\u3002<br \/>\n(\u30a8\u30e9\u30fc\u306e\u3068\u304d\u306f\u6587\u5b57\u5217\u3067\u300cE\u300d\u3001\u666e\u901a\u306f\u6570\u5b57\u304c\u5165\u3063\u3066\u308b\u60f3\u5b9a)<br \/>\n \u305d\u308c\u3092li\u3067\u8868\u793a\u3059\u308b\u3088\u3046\u306a\u30b3\u30fc\u30c9\u3067\u3059\u3002<br \/>\n<pre class=\"lang:js decode:true \" >const rows = data.map(v =&gt; {\n  return `\n    &lt;li&gt;${v.temp !== 'E'? v.temp : 'Error'}&lt;\/li&gt;\n  `\n})<\/pre>\n\u5358\u7d14\u306b\u66f8\u304f\u3068\u3001\u3053\u3093\u306a\u611f\u3058\u3067\u4e09\u9805\u6f14\u7b97\u5b50\u5165\u308c\u308b\u611f\u3058\u306b\u306a\u308b\u306e\u3067\u306f\u306a\u3044\u3067\u3057\u3087\u3046\u304b\uff1f<br \/>\n\u3053\u308c\u3060\u3051\u3067\u306a\u304f\u3001\u3055\u3089\u306b\u6761\u4ef6\u304c\u5897\u3048\u3066\u304f\u308b\u3068\u3001\u898b\u6804\u3048\u304c\u60aa\u304f\u306a\u3063\u3066\u3044\u304d\u307e\u3059\u3002\u3002<br \/>\n<br \/>\n\u305d\u3053\u3067\u51e6\u7406\u3092Proxy\u306b\u4efb\u305b\u3066\u307f\u307e\u3057\u3087\u3046\u3002<br \/>\n<pre class=\"lang:js decode:true \" >const rows = data.map(v =&gt; {\n  const proxy = new Proxy(v, {\n    get(target, name) {\n       if (name === 'temp' &amp;&amp; target[name] === 'E') {\n           return 'Error'\n       }\n       return target[name]\n    }\n  })\n  return `\n    &lt;li&gt;${proxy.temp}&lt;\/li&gt;\n  `\n})<\/pre>\n\u3053\u3093\u306a\u611f\u3058\u3067\u3001HTML\u3092\u7d44\u307f\u7acb\u3066\u308b\u3068\u3053\u308d\u304c\u30b9\u30c3\u30ad\u30ea\u3057\u307e\u3059\u3002<br \/>\n\u3055\u3089\u306b\u300c\u6b20\u640d\u5024\u306b\u306fnull\u304c\u5165\u308b\u304b\u3089\u3001\u7a7a\u3067\u8868\u793a\u3055\u305b\u3066\u307b\u3057\u3044\u300d\u306a\u3093\u3066\u8981\u671b\u304c\u304d\u305f\u3068\u3057\u3066\u3082\u3001get\u306e\u4e2d\u306b\u66f8\u3044\u3066\u3057\u307e\u3048\u3070\u3001HTML\u3092\u7d44\u307f\u7acb\u3066\u3066\u3044\u308b\u90e8\u5206\u306b\u306f\u5f71\u97ff\u3057\u307e\u305b\u3093\u3002<br \/>\n<br \/>\n\u4e88\u60f3\u5916\u306e\u30c7\u30fc\u30bf\u304c\u98db\u3073\u8fbc\u3093\u3067\u304f\u308b\u3053\u3068\u304c\u591a\u3044\u5834\u5408\u306b\u306f\u7d50\u69cb\u6709\u7528\u3060\u3068\u601d\u3063\u3066\u307e\u3059\u3002<br \/>\n<br \/>\n\u3053\u306e\u3088\u3046\u306a\u30d1\u30bf\u30fc\u30f3\u3067\u56f0\u3063\u3066\u3044\u308b\u3053\u3068\u304c\u3042\u308c\u3070\u3001\u6d3b\u7528\u3057\u3066\u307f\u3066\u304f\u3060\u3055\u3044\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6e9d\u7551\u3067\u3059\u3002 \u4eca\u65e5\u306fProxy\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306b\u3064\u3044\u3066\u3002 JavaScript\u66f8\u3044\u3066\u3044 &hellip; <a href=\"https:\/\/www.key-p.com\/blog\/staff\/archives\/107669\">\u7d9a\u304d\u3092\u8aad\u3080 <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":33,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[16],"tags":[],"jetpack-related-posts":[],"_links":{"self":[{"href":"https:\/\/www.key-p.com\/blog\/staff\/wp-json\/wp\/v2\/posts\/107669"}],"collection":[{"href":"https:\/\/www.key-p.com\/blog\/staff\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.key-p.com\/blog\/staff\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.key-p.com\/blog\/staff\/wp-json\/wp\/v2\/users\/33"}],"replies":[{"embeddable":true,"href":"https:\/\/www.key-p.com\/blog\/staff\/wp-json\/wp\/v2\/comments?post=107669"}],"version-history":[{"count":13,"href":"https:\/\/www.key-p.com\/blog\/staff\/wp-json\/wp\/v2\/posts\/107669\/revisions"}],"predecessor-version":[{"id":107682,"href":"https:\/\/www.key-p.com\/blog\/staff\/wp-json\/wp\/v2\/posts\/107669\/revisions\/107682"}],"wp:attachment":[{"href":"https:\/\/www.key-p.com\/blog\/staff\/wp-json\/wp\/v2\/media?parent=107669"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.key-p.com\/blog\/staff\/wp-json\/wp\/v2\/categories?post=107669"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.key-p.com\/blog\/staff\/wp-json\/wp\/v2\/tags?post=107669"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}