{"id":5457,"date":"2018-07-07T11:17:47","date_gmt":"2018-07-07T02:17:47","guid":{"rendered":"http:\/\/www.code-magagine.com\/?p=5457"},"modified":"2023-05-27T21:02:28","modified_gmt":"2023-05-27T12:02:28","slug":"%e3%80%90javascript%e3%80%91%e3%80%8cthis%e3%82%ad%e3%83%bc%e3%83%af%e3%83%bc%e3%83%89%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=5457","title":{"rendered":"\u3010JavaScript\u3011\u300cthis\u30ad\u30fc\u30ef\u30fc\u30c9\u300d\u306b\u3064\u3044\u3066"},"content":{"rendered":"<h2>this\u30ad\u30fc\u30ef\u30fc\u30c9\u3068\u306f\uff1f<\/h2>\n<p>JavaScript\u3067\u3001\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3092new\u3057\u305f\u969b\u306b\u3001\u30b3\u30f3\u30b9\u30c8\u30e9\u30af\u30bf\u304c\u547c\u3073\u51fa\u3055\u308c\u307e\u3059\u304c\u3001<span style=\"color: #ff0000;\"><strong>\u30b3\u30f3\u30b9\u30c8\u30e9\u30af\u30bf\u306b\u3088\u3063\u3066\u751f\u6210\u3055\u308c\u308b\u30a4\u30f3\u30b9\u30bf\u30f3\u30b9\u306e\u3053\u3068<\/strong><\/span>\u3067\u3059\u3002<\/p>\n<h2>this\u30ad\u30fc\u30ef\u30fc\u30c9\u306e\u7279\u5fb4<\/h2>\n<p>this\u30ad\u30fc\u30ef\u30fc\u30c9\u306f\u4e0b\u8a18\u306e\u7279\u5fb4\u3092\u6301\u3064\u306e\u3067\u6271\u3044\u306b\u306f\u975e\u5e38\u306b\u614e\u91cd\u306b\u306a\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002<\/p>\n<ul>\n<li>\u30b9\u30af\u30ea\u30d7\u30c8\u306e\u3069\u3053\u304b\u3089\u3067\u3082\u53c2\u7167\u3067\u304d\u308b\u7279\u5225\u306a\u5909\u6570<\/li>\n<li>\u547c\u3073\u51fa\u3059\u5834\u6240\u3084\u3001\u547c\u3073\u51fa\u3057\u306e\u65b9\u6cd5\u306b\u3088\u3063\u3066\u4e2d\u8eab\u304c\u5909\u308f\u308b\u3002<\/li>\n<\/ul>\n<h2>\u547c\u3073\u51fa\u3059\u5834\u6240\u306b\u3088\u308b\u300cthis\u30ad\u30fc\u30ef\u30fc\u30c9\u306e\u4e2d\u8eab\u300d<\/h2>\n<table>\n<tbody>\n<tr>\n<th>\u547c\u3073\u51fa\u3059\u5834\u6240<\/th>\n<th>this\u306e\u53c2\u7167\u5148<\/th>\n<\/tr>\n<tr>\n<td>class\u306e\u4e2d<\/td>\n<td>class\u306e\u30a4\u30f3\u30b9\u30bf\u30f3\u30b9<\/td>\n<\/tr>\n<tr>\n<td>\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306e\u4e2d<\/td>\n<td>\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u305d\u306e\u3082\u306e<\/td>\n<\/tr>\n<tr>\n<td>\u95a2\u6570\u306e\u5916<\/td>\n<td>\u30b0\u30ed\u30fc\u30d0\u30eb\u30aa\u30d6\u30b8\u30a7\u30af\u30c8<\/td>\n<\/tr>\n<tr>\n<td>\u95a2\u6570\u306e\u4e2d<\/td>\n<td>\u30b0\u30ed\u30fc\u30d0\u30eb\u30aa\u30d6\u30b8\u30a7\u30af\u30c8(Strict\u30e2\u30fc\u30c9\u3067\u306f\u3001undefined)<\/td>\n<\/tr>\n<tr>\n<td>call\/apply\u30e1\u30bd\u30c3\u30c9<\/td>\n<td>\u5f15\u6570\u3067\u6307\u5b9a\u3055\u308c\u305f\u30aa\u30d6\u30b8\u30a7\u30af\u30c8<\/td>\n<\/tr>\n<tr>\n<td>\u30a4\u30d9\u30f3\u30c8\u30ea\u30b9\u30ca\u30fc<\/td>\n<td>\u30a4\u30d9\u30f3\u30c8\u306e\u767a\u751f\u5143<\/td>\n<\/tr>\n<tr>\n<td>\u30b3\u30f3\u30b9\u30c8\u30e9\u30af\u30bf\u30fc<\/td>\n<td>\u751f\u6210\u3057\u305f\u30a4\u30f3\u30b9\u30bf\u30f3\u30b9<\/td>\n<\/tr>\n<tr>\n<td>\u30e1\u30bd\u30c3\u30c9<\/td>\n<td>\u547c\u3073\u51fa\u3057\u3082\u3068\u306e\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\uff08\u30ec\u30b7\u30fc\u30d0\u30fc\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\uff09<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>call\/apply\u30e1\u30bd\u30c3\u30c9\u306b\u3064\u3044\u3066\u306f\u4e0b\u8a18\u306e\u8a18\u4e8b\u3067\u89e3\u8aac\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n<blockquote class=\"wp-embedded-content\" data-secret=\"4EPoztG7hJ\"><p><a href=\"http:\/\/www.code-magagine.com\/?p=5464\">\u3010JavaScript\u3011\u300ccall\/apply\/bind\u30e1\u30bd\u30c3\u30c9\u300d\u306b\u3064\u3044\u3066<\/a><\/p><\/blockquote>\n<p><iframe class=\"wp-embedded-content\" sandbox=\"allow-scripts\" security=\"restricted\" style=\"position: absolute; clip: rect(1px, 1px, 1px, 1px);\" src=\"http:\/\/www.code-magagine.com\/?p=5464&#038;embed=true#?secret=4EPoztG7hJ\" data-secret=\"4EPoztG7hJ\" width=\"500\" height=\"282\" title=\"&#8220;\u3010JavaScript\u3011\u300ccall\/apply\/bind\u30e1\u30bd\u30c3\u30c9\u300d\u306b\u3064\u3044\u3066&#8221; &#8212; \u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0\u30de\u30ac\u30b8\u30f3\" frameborder=\"0\" marginwidth=\"0\" marginheight=\"0\" scrolling=\"no\"><\/iframe><\/p>\n<h3>\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306e\u4e2d<\/h3>\n<p>\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306e\u4e2d\u306ethis\u306b\u95a2\u3057\u3066\u306f\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u4f7f\u3063\u305f\u308a\u3057\u307e\u3059\u3002<\/p>\n<pre class=\"lang:default decode:true \">const person = {\r\n  name: \"\u592a\u90ce\",\r\n  age: 24,\r\n  setAge: function (age) {\r\n    this.age = age;\r\n  },\r\n};\r\n\r\nconsole.log(person); \/\/ age=24\r\nperson.setAge(34);\r\nconsole.log(person); \/\/ age=34\r\n<\/pre>\n<h3>\u30a2\u30ed\u30fc\u95a2\u6570\u306e\u5834\u5408<\/h3>\n<p>ES6\u304b\u3089\u767b\u5834\u3057\u305f\u30a2\u30ed\u30fc\u95a2\u6570\u3092\u4f7f\u3063\u305f\u5834\u5408\u306f\u901a\u5e38\u306e\u95a2\u6570\u5ba3\u8a00\u3068\u7570\u306a\u308a<span style=\"color: #ff0000;\"><strong>this\u306f\u4e00\u3064\u89aa\u306e\u30b9\u30b3\u30fc\u30d7\u306e\u7269\u3092\u4f7f\u3046<\/strong><\/span>\u3088\u3046\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<h4>\u666e\u901a\u306e\u95a2\u6570\u3092\u4f7f\u3063\u305f\u5834\u5408<\/h4>\n<pre class=\"lang:default decode:true\">let obj = {\r\n  value: 5,\r\n  kansu: function () {\r\n    setTimeout(function () {\r\n      console.log(this.value); \/\/this\u3067\u306f\u89aa\u30b9\u30b3\u30fc\u30d7\u3067\u3042\u308bobj\u30d6\u30ed\u30c3\u30af\u306evalue\u3092\u53c2\u7167\u3067\u304d\u306a\u3044\u3002\r\n    }, 1000)\r\n  }\r\n}\r\n\r\nobj.kansu();<\/pre>\n<h4>\u30a2\u30ed\u30fc\u95a2\u6570\u3092\u4f7f\u3063\u305f\u5834\u5408<\/h4>\n<pre class=\"lang:default decode:true\">let obj = {\r\n  value: 5,\r\n  kansu: function () {\r\n    setTimeout(() =&gt; {\r\n      console.log(this.value); \/\/\u89aa\u30b9\u30b3\u30fc\u30d7\u306evalue\u3092\u53c2\u7167\u3059\u308b\u4e8b\u304c\u3067\u304d\u308b\u3002\r\n    }, 1000)\r\n  }\r\n}\r\n\r\nobj.kansu();<\/pre>\n<p>\u305f\u3060\u3001\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u3055\u3089\u306b\u547c\u3073\u51fa\u3057\u5143\u306e\u95a2\u6570\u3082\u30a2\u30ed\u30fc\u95a2\u6570\u3068\u3059\u308b\u3068\u305d\u306e\u4e0b\u306e\u30b9\u30b3\u30fc\u30d7\u3067this\u306b\u3088\u308a\u53c2\u7167\u3067\u304d\u306a\u304f\u306a\u308a\u307e\u3059\u3002\u3053\u308c\u306f<span style=\"color: #ff0000;\"><strong>this\u304c\u3055\u3089\u306b\u4e0a\u306e\u30b9\u30b3\u30fc\u30d7\u3067\u3042\u308b\u30b0\u30ed\u30fc\u30d0\u30eb\u30b9\u30b3\u30fc\u30d7\u3092\u53c2\u7167\u3059\u308b\u3088\u3046\u306b\u306a\u3063\u3066\u3057\u307e\u3046\u305f\u3081<\/strong><\/span>\u3067\u3059\u3002<span style=\"color: #ff0000;\"><strong>\u30a2\u30ed\u30fc\u95a2\u6570\u3092\u4f7f\u3063\u305f\u304b\u3089\u3068\u8a00\u3063\u3066this\u306e\u6271\u3044\u65b9\u306b\u95a2\u3057\u3066\u306f\u4e07\u80fd\u3067\u306f\u306a\u3044<\/strong><\/span>\u306e\u3067\u6ce8\u610f\u3057\u307e\u3057\u3087\u3046\u3002<\/p>\n<pre class=\"lang:default decode:true\">let obj = {\r\n  value: 5,\r\n  kansu: () =&gt; { \/\/\u30a2\u30ed\u30fc\u95a2\u6570\u306b\u5909\u66f4\r\n    setTimeout(() =&gt; {\r\n      console.log(this.value); \/\/\u89aa\u30b9\u30b3\u30fc\u30d7\u306evalue\u3092\u53c2\u7167\u3059\u308b\u4e8b\u304c\u3067\u304d\u306a\u304f\u306a\u308b\u3002\r\n    }, 1000)\r\n  }\r\n}\r\n\r\nobj.kansu();<\/pre>\n<h3>Vue.js\u306e\u5834\u5408<\/h3>\n<p>Vue.js\u3067this\u3092\u6307\u5b9a\u3057\u305f\u5834\u5408\u306f\u4e0b\u8a18\u306e\u3088\u3046\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<table>\n<tbody>\n<tr>\n<th>this\u306e\u6307\u5b9a\u5834\u6240<\/th>\n<th>\u8aac\u660e<\/th>\n<\/tr>\n<tr>\n<td>Vue()\u306e\u5185\u5074\u306e\u30ed\u30fc\u30ab\u30eb\u30b9\u30b3\u30fc\u30d7<\/td>\n<td>Vue\u30a4\u30f3\u30b9\u30bf\u30f3\u30b9\u3092\u6307\u3057\u307e\u3059\u3002<\/td>\n<\/tr>\n<tr>\n<td>Vue()\u306e\u5916\u5074\u306e\u30b0\u30ed\u30fc\u30d0\u30eb\u30b9\u30b3\u30fc\u30d7<\/td>\n<td>\u30d6\u30e9\u30a6\u30b6\u306ewindow\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3092\u6307\u3057\u307e\u3059\u3002<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h2>\u30b3\u30f3\u30b9\u30c8\u30e9\u30af\u30bf\u306e\u6ce8\u610f\u70b9<\/h2>\n<p>JavaScript\u3067\u306f\u3001\u30b3\u30f3\u30b9\u30c8\u30e9\u30af\u30bf\u3082\u95a2\u6570\u3068\u3057\u3066\u547c\u3073\u51fa\u3059\u3053\u3068\u304c\u53ef\u80fd\u3067\u3059\u3002<\/p>\n<p>\u3057\u304b\u3057\u3001\u95a2\u6570\u3067\u547c\u3073\u51fa\u3057\u305f\u30b3\u30f3\u30b9\u30c8\u30e9\u30af\u30bf\u306e\u5834\u5408\u306f\u3001this\u30ad\u30fc\u30ef\u30fc\u30c9\u3092\u4f7f\u3046\u3068\u3001<span style=\"color: #ff0000;\"><strong>\u30a4\u30f3\u30b9\u30bf\u30f3\u30b9\u5909\u6570\u3067\u306f\u306a\u304f\u3001\u666e\u901a\u306b\u30b0\u30ed\u30fc\u30d0\u30eb\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306b\u5024\u304c\u683c\u7d0d\u3055\u308c\u3066\u3057\u307e\u3044\u307e\u3059\u3002<\/strong><\/span><\/p>\n<p>\u30d0\u30b0\u306e\u5143\u306b\u306a\u308b\u306e\u3067\u6ce8\u610f\u3057\u307e\u3057\u3087\u3046\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"this\u30ad\u30fc\u30ef\u30fc\u30c9\u3068\u306f\uff1f JavaScript\u3067\u3001\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3092new\u3057\u305f\u969b\u306b\u3001\u30b3\u30f3\u30b9\u30c8\u30e9\u30af\u30bf\u304c\u547c\u3073\u51fa\u3055\u308c\u307e\u3059\u304c\u3001\u30b3\u30f3\u30b9\u30c8\u30e9\u30af\u30bf\u306b\u3088\u3063\u3066\u751f\u6210\u3055\u308c\u308b\u30a4\u30f3\u30b9\u30bf\u30f3\u30b9\u306e\u3053\u3068\u3067\u3059\u3002 this\u30ad\u30fc\u30ef\u30fc\u30c9\u306e\u7279\u5fb4 this\u30ad\u30fc\u30ef\u30fc\u30c9\u306f\u4e0b [&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\/5457"}],"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=5457"}],"version-history":[{"count":17,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=\/wp\/v2\/posts\/5457\/revisions"}],"predecessor-version":[{"id":20304,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=\/wp\/v2\/posts\/5457\/revisions\/20304"}],"wp:attachment":[{"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=5457"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=5457"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=5457"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}