{"id":5464,"date":"2018-07-07T11:26:26","date_gmt":"2018-07-07T02:26:26","guid":{"rendered":"http:\/\/www.code-magagine.com\/?p=5464"},"modified":"2023-05-27T21:02:11","modified_gmt":"2023-05-27T12:02:11","slug":"%e3%80%90javascript%e3%80%91%e3%80%8ccall-apply%e3%83%a1%e3%82%bd%e3%83%83%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=5464","title":{"rendered":"\u3010JavaScript\u3011\u300ccall\/apply\/bind\u30e1\u30bd\u30c3\u30c9\u300d\u306b\u3064\u3044\u3066"},"content":{"rendered":"<h2>call\/apply\/bind\u30e1\u30bd\u30c3\u30c9\u3068\u306f\uff1f<\/h2>\n<p>\u3044\u305a\u308c\u3082<span style=\"color: #ff0000;\"><strong>\u95a2\u6570\uff08Function\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\uff09\u304c\u63d0\u4f9b\u3059\u308b\u30e1\u30f3\u30d0\u30fc<\/strong><\/span>\u306e\u3053\u3068\u3067\u3001\u305d\u306e\u95a2\u6570\u3092\u547c\u3073\u51fa\u3059\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002\u95a2\u6570\u306e\u547c\u3073\u51fa\u3057\u5074\u3067this\u3092\u6307\u5b9a\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3088\u3068\u3044\u3046\u3082\u306e\u3067\u3059\u3002<\/p>\n<h3>call<\/h3>\n<p>call\u3067\u79c1\u305f\u7b2c\u4e00\u5f15\u6570\u304c\u6e21\u3057\u305f\u95a2\u6570\u5185\u306ethis\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<pre class=\"lang:default decode:true\">const func = function () {\r\n  console.log(this);\r\n};\r\nfunc.call({ name: \"\u592a\u90ce\" });<\/pre>\n<p>\u901a\u5e38\u3060\u3068\u3001this\u306e\u4e2d\u8eab\u306fwindow\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3001strict\u30e2\u30fc\u30c9\u3060\u3068undefined\u306b\u306a\u308b\u306e\u3067this\u306e\u4e2d\u8eab\u3092\u95a2\u6570\u306e\u5916\u90e8\u304b\u3089\u5909\u66f4\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u308b\u3068\u3044\u3046\u308f\u3051\u3067\u3059\u306d\u3002<\/p>\n<h3>apply<\/h3>\n<p>\u4ee5\u4e0b\u306e\u4f8b\u3067\u306fcall\u3068\u5168\u304f\u540c\u3058\u6319\u52d5\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<pre class=\"lang:default decode:true\">const func = function () {\r\n  console.log(this);\r\n};\r\nfunc.apply({ name: \"\u592a\u90ce\" });\r\n<\/pre>\n<h3>bind<\/h3>\n<p>call\/apply\u3068\u9055\u3063\u3066\u5143\u306e\u95a2\u6570\u3092\u4f7f\u3063\u3066\u65b0\u3057\u3044\u95a2\u6570\u3092\u4f5c\u308a\u51fa\u3059\u3053\u3068\u304c\u3067\u304d\u308b\u30e1\u30bd\u30c3\u30c9\u306b\u306a\u308a\u307e\u3059\u3002\u306a\u306e\u3067\u65b0\u3057\u3044\u95a2\u6570\u3092\u5909\u6570\u306b\u4ee3\u5165\u3057\u3066\u5b9f\u884c\u3059\u308b\u5f62\u3067\u4f7f\u3044\u307e\u3059\u3002<\/p>\n<pre class=\"lang:default decode:true\">const func = function () {\r\n  console.log(this);\r\n};\r\nconst bindFunc = func.bind({ name: \"\u592a\u90ce\" });\r\nbindFunc();<\/pre>\n<h4>bind\u306e\u6ce8\u610f\u70b9<\/h4>\n<p>bind\u3067\u751f\u6210\u3055\u308c\u305f\u95a2\u6570\u306b\u5bfe\u3057\u3066call\u3084apply\u3067\u307e\u305fthis\u3092\u6307\u5b9a\u3057\u3088\u3046\u3068\u3057\u3066\u3082bind\u3067\u751f\u6210\u3057\u305f\u30d1\u30e9\u30e1\u30fc\u30bf\u3067\u56fa\u5b9a\u3055\u308c\u307e\u3059\u3002<\/p>\n<h2>call\u3068apply\u306e\u9055\u3044<\/h2>\n<p>\u5b9f\u884c\u3059\u3079\u304d\u95a2\u6570func\u306b\u6e21\u3059\u5f15\u6570\u306e\u6307\u5b9a\u65b9\u6cd5\u304c\u7570\u306a\u308b\u3060\u3051\u3067\u57fa\u672c\u7684\u306b\u306f\u540c\u3058\u3067\u3059\u3002\u95a2\u6570\u306b\u5f15\u6570\u3092\u6307\u5b9a\u3057\u305f\u3068\u304d\u306e\u30d1\u30e9\u30e1\u30fc\u30bf\u306e\u6307\u5b9a\u65b9\u6cd5\u304c\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u7570\u306a\u308a\u307e\u3059\u3002<\/p>\n<pre class=\"lang:default decode:true\">const func = function (a, b) {\r\n  console.log(this, a, b);\r\n};\r\nfunc.call({ name: \"\u592a\u90ce\" }, 1, 2); \/\/ \u500b\u5225\u306b\u5f15\u6570\u3092\u6e21\u3059\u3002\r\nfunc.apply({ name: \"\u592a\u90ce\" }, [1, 2]);\/\/ \u914d\u5217\u306b\u3057\u3066\u5f15\u6570\u3092\u6e21\u3059\u3002<\/pre>\n<p>\u7d50\u8ad6\u304b\u3089\u8a00\u3048\u3070\u3001\u7279\u306b\u9055\u3044\u306f\u306a\u3044\u306e\u3067\u597d\u304d\u306a\u65b9\u3092\u4f7f\u3048\u3070\u826f\u3044\u3067\u3059\u3002<\/p>\n<h2>call\/apply\u30e1\u30bd\u30c3\u30c9\u306e\u30e1\u30ea\u30c3\u30c8<\/h2>\n<p>\u914d\u5217\u306b\u4f3c\u3066\u3044\u308b\u304c\u3001\u914d\u5217\u3067\u306f\u306a\u3044\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3092\u3001\u914d\u5217\u306b\u5909\u63db\u3057\u305f\u308a\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002\uff08\u4f8b\u3048\u3070\u3001<span style=\"color: #ff0000;\"><strong>arguments\u30aa\u30d6\u30b8\u30a7\u30af\u30c8<\/strong><\/span>\u306e\u3088\u3046\u306b\uff09<\/p>\n<h2>\u6ce8\u610f\u70b9<\/h2>\n<p>\u30a2\u30ed\u30fc\u95a2\u6570\u306b\u306fcall\u3082apply\u3082\u5b58\u5728\u3057\u306a\u3044\u3067\u3059\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"call\/apply\/bind\u30e1\u30bd\u30c3\u30c9\u3068\u306f\uff1f \u3044\u305a\u308c\u3082\u95a2\u6570\uff08Function\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\uff09\u304c\u63d0\u4f9b\u3059\u308b\u30e1\u30f3\u30d0\u30fc\u306e\u3053\u3068\u3067\u3001\u305d\u306e\u95a2\u6570\u3092\u547c\u3073\u51fa\u3059\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002\u95a2\u6570\u306e\u547c\u3073\u51fa\u3057\u5074\u3067this\u3092\u6307\u5b9a\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3088\u3068\u3044\u3046\u3082\u306e\u3067\u3059\u3002 [&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\/5464"}],"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=5464"}],"version-history":[{"count":9,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=\/wp\/v2\/posts\/5464\/revisions"}],"predecessor-version":[{"id":20303,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=\/wp\/v2\/posts\/5464\/revisions\/20303"}],"wp:attachment":[{"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=5464"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=5464"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=5464"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}