{"id":1420,"date":"2023-03-11T14:25:52","date_gmt":"2023-03-11T05:25:52","guid":{"rendered":"http:\/\/attacktube.com\/?p=1420"},"modified":"2023-06-04T13:53:26","modified_gmt":"2023-06-04T04:53:26","slug":"%e3%80%90javascript%e3%80%91arguments%e3%82%aa%e3%83%96%e3%82%b8%e3%82%a7%e3%82%af%e3%83%88%e3%82%92%e9%85%8d%e5%88%97array%e3%81%ab%e5%a4%89%e6%8f%9b%e3%81%99%e3%82%8b","status":"publish","type":"post","link":"https:\/\/attacktube.com\/?p=1420","title":{"rendered":"\u3010JavaScript\u3011arguments\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3092\u914d\u5217(Array)\u306b\u5909\u63db\u3059\u308b"},"content":{"rendered":"\n<p>arguments\u306flength\u30d7\u30ed\u30d1\u30c6\u30a3\u3092\u6301\u3063\u3066\u3044\u308b\u3002<br>\u3057\u304b\u3057\u3001\u914d\u5217\u3067\u306f\u306a\u304f\u914d\u5217\u98a8\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3067\u3042\u308b\u3002<br>\u6700\u8fd1\u306e\u30b3\u30fc\u30c6\u30a3\u30f3\u30b0\u3067\u306ffor\u6587\u306e\u4ee3\u308f\u308a\u306bforEach\u6587\u3092\u4f7f\u3046\u304c\u3001arguments\u306bforEach\u6587\u3092\u4f7f\u3046\u306b\u306farguments\u3092\u914d\u5217\u306b\u5909\u63db\u3059\u308b\u5fc5\u8981\u304c\u3042\u308b\u3002<br>Array.prototype.slice.call(\u914d\u5217\u98a8\u30aa\u30d6\u30b8\u30a7\u30af\u30c8)\u3067\u914d\u5217\u98a8\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3092\u914d\u5217\u306b\u5909\u63db\u3059\u308b\u3002<br>arguments\u306fArray.prototype.slice.call(\u914d\u5217\u98a8\u30aa\u30d6\u30b8\u30a7\u30af\u30c8)\u3067\u914d\u5217\u306b\u5909\u63db\u5f8c\u306bforeach\u30e1\u30bd\u30c3\u30c9\u3092\u4f7f\u3046\u3002<br>Array.prototype.slice.call(\u914d\u5217\u98a8\u30aa\u30d6\u30b8\u30a7\u30af\u30c8)\u3092\u7701\u7565\u3057\u3066\u66f8\u304f\u3068[].slice.call(\u914d\u5217\u98a8\u30aa\u30d6\u30b8\u30a7\u30af\u30c8)\u3068\u306a\u308b\u3002<br><br>JavaScript\u306e\u4ed5\u69d8\u3067\u306fArray.prototype.slice.call(\u914d\u5217\u98a8\u30aa\u30d6\u30b8\u30a7\u30af\u30c8)\u306b\u3088\u308b\u9806\u5e8f\u306e\u4fdd\u8a3c\u306f\u660e\u793a\u3055\u308c\u3066\u3044\u306a\u3044\u3002\u305f\u3060\u3057\u3001\u591a\u304f\u306e\u74b0\u5883\u3084\u5b9f\u88c5\u3067\u306f\u3001slice\u30e1\u30bd\u30c3\u30c9\u304c\u914d\u5217\u98a8\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306e\u8981\u7d20\u3092\u9806\u756a\u306b\u30b3\u30d4\u30fc\u3059\u308b\u305f\u3081\u3001\u9806\u5e8f\u304c\u4fdd\u8a3c\u3055\u308c\u308b\u3053\u3068\u304c\u4e00\u822c\u7684\u3067\u3042\u308b\u3002<\/p>\n\n\n\n<!--more-->\n\n\n\n<br>\n<script async=\"\" src=\"https:\/\/pagead2.googlesyndication.com\/pagead\/js\/adsbygoogle.js?client=ca-pub-3461056110605997\" crossorigin=\"anonymous\"><\/script>\n<ins class=\"adsbygoogle\" style=\"display:block; text-align:center;\" data-ad-layout=\"in-article\" data-ad-format=\"fluid\" data-ad-client=\"ca-pub-3461056110605997\" data-ad-slot=\"3137443461\"><\/ins>\n<script>\n     (adsbygoogle = window.adsbygoogle || []).push({});\n<\/script>\n<br>\n\n\n\n<pre><code>\nlet add1 = function() {\n\n    let sum = 0;\n\n    \/\/slice.call(\u30aa\u30d6\u30b8\u30a7\u30af\u30c8)\u3067\u914d\u5217\u98a8\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3092\u914d\u5217\u306b\u5909\u63db\u3059\u308b\u3002\n    const newArgs = Array.prototype.slice.call(arguments);\n\n    console.log(&quot;Array.isArray(arguments) = &quot; + Array.isArray(arguments));\n    console.log(&quot;Array.isArray(newArgs) = &quot; + Array.isArray(newArgs));\n\n    newArgs.forEach((element,i) =&gt; {\n        sum += element;\n        console.log(&quot;Array.prototype.slice.call(arguments) element = &quot; + element + &quot;, i = &quot; + i);\n    });\n\n    return sum;\n};\n\nlet add2 = function() {\n    let sum = 0;\n\n    \/\/slice.call(\u30aa\u30d6\u30b8\u30a7\u30af\u30c8)\u3067\u914d\u5217\u98a8\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3092\u914d\u5217\u306b\u5909\u63db\u3059\u308b\u3002\n    const newArgs = [].slice.call(arguments);\n\n    console.log(&quot;Array.isArray(arguments) = &quot; + Array.isArray(arguments));\n    console.log(&quot;Array.isArray(newArgs) = &quot; + Array.isArray(newArgs));\n\n    newArgs.forEach((element, i) =&gt; {\n        sum += element;\n        console.log(&quot;[].slice.call(arguments) element = &quot; + element + &quot;, i = &quot; + i);\n    });\n\n    return sum;\n\n};\n\nconsole.log(&quot;add1(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20) = &quot; + add1(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20));\n\nconsole.log(&quot;add2(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20) = &quot; + add2(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20));\n\n\/*\n\nArray.isArray(arguments) = false\nArray.isArray(newArgs) = true\nArray.prototype.slice.call(arguments) element = 1, i = 0\nArray.prototype.slice.call(arguments) element = 2, i = 1\nArray.prototype.slice.call(arguments) element = 3, i = 2\nArray.prototype.slice.call(arguments) element = 4, i = 3\nArray.prototype.slice.call(arguments) element = 5, i = 4\nArray.prototype.slice.call(arguments) element = 6, i = 5\nArray.prototype.slice.call(arguments) element = 7, i = 6\nArray.prototype.slice.call(arguments) element = 8, i = 7\nArray.prototype.slice.call(arguments) element = 9, i = 8\nArray.prototype.slice.call(arguments) element = 10, i = 9\nArray.prototype.slice.call(arguments) element = 11, i = 10\nArray.prototype.slice.call(arguments) element = 12, i = 11\nArray.prototype.slice.call(arguments) element = 13, i = 12\nArray.prototype.slice.call(arguments) element = 14, i = 13\nArray.prototype.slice.call(arguments) element = 15, i = 14\nArray.prototype.slice.call(arguments) element = 16, i = 15\nArray.prototype.slice.call(arguments) element = 17, i = 16\nArray.prototype.slice.call(arguments) element = 18, i = 17\nArray.prototype.slice.call(arguments) element = 19, i = 18\nArray.prototype.slice.call(arguments) element = 20, i = 19\nadd1(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20) = 210\nArray.isArray(arguments) = false\nArray.isArray(newArgs) = true\n[].slice.call(arguments) element = 1, i = 0\n[].slice.call(arguments) element = 2, i = 1\n[].slice.call(arguments) element = 3, i = 2\n[].slice.call(arguments) element = 4, i = 3\n[].slice.call(arguments) element = 5, i = 4\n[].slice.call(arguments) element = 6, i = 5\n[].slice.call(arguments) element = 7, i = 6\n[].slice.call(arguments) element = 8, i = 7\n[].slice.call(arguments) element = 9, i = 8\n[].slice.call(arguments) element = 10, i = 9\n[].slice.call(arguments) element = 11, i = 10\n[].slice.call(arguments) element = 12, i = 11\n[].slice.call(arguments) element = 13, i = 12\n[].slice.call(arguments) element = 14, i = 13\n[].slice.call(arguments) element = 15, i = 14\n[].slice.call(arguments) element = 16, i = 15\n[].slice.call(arguments) element = 17, i = 16\n[].slice.call(arguments) element = 18, i = 17\n[].slice.call(arguments) element = 19, i = 18\n[].slice.call(arguments) element = 20, i = 19\nadd2(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20) = 210\n\n*\/\n<\/code><\/pre>\n\n\n\n<p><a href=\"https:\/\/qiita.com\/LightSpeedC\/items\/5cf07f94b051d0a8d4f1\">arguments\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3092\u914d\u5217(Array)\u306b\u3059\u308b\u65b9\u6cd5 &#8211; Qiita<\/a> ExternalLink<br><a href=\"https:\/\/www.konosumi.net\/entry\/2019\/05\/26\/220321\">JavaScript\u306e\u914d\u5217\u98a8\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3068\u300c[].slice.call()\u300d\u306b\u3088\u308b\u914d\u5217\u5909\u63db\u306b\u3064\u3044\u3066 &#8211; \u3053\u306e\u3059\u307f\u30ce\u30fc\u30c8 (konosumi.net)<\/a> ExternalLink<\/p>\n\n\n\n<br>\n<script async=\"\" src=\"https:\/\/pagead2.googlesyndication.com\/pagead\/js\/adsbygoogle.js?client=ca-pub-3461056110605997\" crossorigin=\"anonymous\"><\/script>\n<ins class=\"adsbygoogle\" style=\"display:block; text-align:center;\" data-ad-layout=\"in-article\" data-ad-format=\"fluid\" data-ad-client=\"ca-pub-3461056110605997\" data-ad-slot=\"3137443461\"><\/ins>\n<script>\n     (adsbygoogle = window.adsbygoogle || []).push({});\n<\/script>\n<br>\n\n\n\n<script type=\"text\/javascript\">\njQuery(function($){\n$(\".jp-video\").hide();\n});\n<\/script>\n","protected":false},"excerpt":{"rendered":"<p>arguments\u306flength\u30d7\u30ed\u30d1\u30c6\u30a3\u3092\u6301\u3063\u3066\u3044\u308b\u3002\u3057\u304b\u3057\u3001\u914d\u5217\u3067\u306f\u306a\u304f\u914d\u5217\u98a8\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3067\u3042\u308b\u3002\u6700\u8fd1\u306e\u30b3\u30fc\u30c6\u30a3\u30f3\u30b0\u3067\u306ffor\u6587\u306e\u4ee3\u308f\u308a\u306bforEach\u6587\u3092\u4f7f\u3046\u304c\u3001arguments\u306bforEach\u6587\u3092\u4f7f\u3046\u306b\u306farg [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[3],"tags":[],"class_list":["post-1420","post","type-post","status-publish","format-standard","hentry","category-javascript"],"jetpack_featured_media_url":"","jetpack-related-posts":[],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/attacktube.com\/index.php?rest_route=\/wp\/v2\/posts\/1420","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/attacktube.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/attacktube.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/attacktube.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/attacktube.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1420"}],"version-history":[{"count":15,"href":"https:\/\/attacktube.com\/index.php?rest_route=\/wp\/v2\/posts\/1420\/revisions"}],"predecessor-version":[{"id":2784,"href":"https:\/\/attacktube.com\/index.php?rest_route=\/wp\/v2\/posts\/1420\/revisions\/2784"}],"wp:attachment":[{"href":"https:\/\/attacktube.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1420"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/attacktube.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1420"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/attacktube.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1420"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}