{"id":15088,"date":"2019-09-16T09:00:48","date_gmt":"2019-09-16T00:00:48","guid":{"rendered":"https:\/\/www.agent-grow.com\/self20percent\/?p=15088"},"modified":"2019-09-09T09:02:07","modified_gmt":"2019-09-09T00:02:07","slug":"javascript-object-and-array-copy-es6","status":"publish","type":"post","link":"https:\/\/www.agent-grow.com\/self20percent\/2019\/09\/16\/javascript-object-and-array-copy-es6\/","title":{"rendered":"[JavaScript] \u30aa\u30d6\u30b8\u30a7\u30af\u30c8 &#038; \u914d\u5217\u306e\u30a4\u30de\u30c9\u30ad\u306a\u30b3\u30d4\u30fc\u65b9\u6cd5 (\u30b9\u30d7\u30ec\u30c3\u30c9\u69cb\u6587)"},"content":{"rendered":"<h1>\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3084\u914d\u5217\u306e\u30b3\u30d4\u30fc\u3063\u3066\u3069\u3046\u3084\u3063\u3066\u66f8\u304d\u307e\u3059\u304b\uff1f<\/h1>\n<p>\u7686\u3055\u3093 JavaScript \u66f8\u3044\u3066\u307e\u3059\u304b\uff1f<\/p>\n<p>JavaScript \u3092\u30ac\u30c3\u30c4\u30ea\u66f8\u3044\u3066\u3044\u308b\u3068\u3001\u305f\u307e\u306b\u5fc5\u8981\u306b\u306a\u308b\u306e\u304c<br \/>\n\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3084\u914d\u5217\u306e\u30b3\u30d4\u30fc\u3002<\/p>\n<p>\u307f\u306a\u3055\u3093\u3069\u3046\u3084\u3063\u3066\u307e\u3059\u304b\uff1f<\/p>\n<p>\u4eca\u56de\u306f\u3001\u30a4\u30de\u30c9\u30ad(ES6)\u306a\u65b9\u6cd5\u3067\u306e\u30b3\u30d4\u30fc\u3092\u3054\u7d39\u4ecb\u3057\u307e\u3057\u3087\u3046\u3002<\/p>\n<h1>\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306e\u30b3\u30d4\u30fc<\/h1>\n<p>\u307e\u305a\u306f\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u304b\u3089\u3002<\/p>\n<p>\u6700\u521d\u306b\u78ba\u8a8d\u3057\u3066\u304a\u304d\u307e\u3059\u304c\u3001\u3082\u3061\u308d\u3093\u3001\u3053\u308c\u306f\u30c0\u30e1\u3067\u3059\u3088\u306d\u3002<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nvar test = { a: 10 };\nvar test_copy = test;\n\ntest_copy.a = 20;\n\nconsole.log(test);\n<\/pre>\n<p><code>test<\/code> \u304b\u3089 <code>test_copy<\/code> \u306b\u4ee3\u5165\u3002<br \/>\n\u3053\u308c\u3067\u306f <code>test<\/code> \u3068 <code>test_copy<\/code> \u306f\u30b3\u30d4\u30fc\u3055\u308c\u3066\u304a\u3089\u305a\u3001\u540c\u3058\u3082\u306e\u3092\u898b\u3066\u3044\u307e\u3059\u3002<\/p>\n<p>\u5b9f\u969b\u5b9f\u884c\u3057\u3066\u307f\u308b\u3068\u2026<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\n&#x5B;object Object] {\n  a: 20\n}\n<\/pre>\n<p><code>test_copy<\/code> \u3092\u5909\u66f4\u3057\u305f\u306f\u305a\u306a\u306e\u306b\u3001 <code>test<\/code> \u306e <code>a<\/code> \u30d7\u30ed\u30d1\u30c6\u30a3\u3082\u5909\u66f4\u3055\u308c\u3066\u3044\u307e\u3059\u306d\u3002<\/p>\n<h2>\u3053\u308c\u307e\u3067\u306e\u65b9\u6cd5<\/h2>\n<p>\u3067\u3001\u3053\u308c\u307e\u3067\u306f\u3053\u3093\u306a\u611f\u3058\u3067\u30b3\u30d4\u30fc\u3057\u3066\u304d\u307e\u3057\u305f\u3002<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nvar test = { a: 10 };\nvar test_copy = Object.assign({}, test);\n<\/pre>\n<p><code>Object.assign()<\/code> \u3092\u4f7f\u3046\u65b9\u6cd5\u3067\u3059\u306d\u3002<br \/>\n\u5143\u3005\u3053\u306e\u95a2\u6570\u306f\u3001\u4e00\u756a\u6700\u521d\u306b\u6e21\u3055\u308c\u305f\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306b\u3001<br \/>\n\u305d\u306e\u5f8c\u308d\u306b\u6e21\u3055\u308c\u305f\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3092\u7d50\u5408\u3057\u3066\u3044\u304f\u95a2\u6570\u3067\u3059\u3002<\/p>\n<p>\u3068\u3044\u3046\u3053\u3068\u3067\u3001\u4eca\u56de\u306f\u65b0\u3057\u304f\u4f5c\u3063\u305f\u7a7a\u30aa\u30d6\u30b8\u30a7\u30af\u30c8 <code>{}<\/code> \u306b<br \/>\ntest \u3092\u7d50\u5408\u3057\u3066\u3044\u308b\u306e\u3067\u3001\u3067\u304d\u3042\u304c\u308b\u5185\u5bb9\u306f test \u3068\u540c\u3058\u3082\u306e\u3060\u3051\u3069\u3001\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u81ea\u4f53\u306f\u5225\u7269\u3068\u306a\u308b\u306e\u3067\u3059\u306d\u3002<\/p>\n<h2>\u30a4\u30de\u30c9\u30ad\u306a\u65b9\u6cd5<\/h2>\n<p>\u6b21\u306b\u3001\u30a4\u30de\u30c9\u30ad\u306a\u65b9\u6cd5\u3067\u30b3\u30d4\u30fc\u3059\u308b\u3068\u3001\u3053\u3046\u3002<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nvar test = { a: 10 };\nvar test_copy = { ...test }\n<\/pre>\n<p>\u306a\u3093\u3060\u304b\u4e0d\u601d\u8b70\u306a\u8a18\u6cd5\u3067\u3059\u304c\u3001\u3084\u3063\u3066\u3044\u308b\u3053\u3068\u306f\u5148\u307b\u3069\u3068\u307b\u307c\u4e00\u7dd2\u3067\u3059\u3002<\/p>\n<p>\u3053\u3053\u3067\u91cd\u8981\u306a\u306e\u306f <code>...test<\/code> \u306e\u90e8\u5206\u3002<\/p>\n<p>\u3053\u308c\u306f\u30b9\u30d7\u30ec\u30c3\u30c9\u69cb\u6587\u3068\u547c\u3070\u308c\u308b\u3082\u306e\u3067\u3001<br \/>\n\u3055\u3063\u304f\u308a\u8aac\u660e\u3059\u308b\u3068\u3001\u305d\u306e\u5834\u3067\u4e2d\u8eab\u3092\u5168\u90e8\u3076\u3061\u307e\u3051\u308b\u3068\u8a00\u3046\u3082\u306e\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<p>https:\/\/developer.mozilla.org\/ja\/docs\/Web\/JavaScript\/Reference\/Operators\/Spread_syntax<\/p>\n<p>\u3064\u307e\u308a\u3001 <code>{ ...test }<\/code> \u306f <code>test<\/code> \u304c\u6301\u3063\u3066\u3044\u308b <code>a: 10<\/code> \u3092\u305d\u306e\u5834\u306b\u5c55\u958b\u3059\u308b\u306e\u3067<br \/>\n<code>{ a: 10 }<\/code> \u3068\u66f8\u3044\u3066\u3044\u308b\u306e\u3068\u540c\u7fa9\u3068\u3044\u3046\u3053\u3068\u306b\u306a\u308a\u307e\u3059\u306d\u3002<\/p>\n<p>\u3088\u3063\u3066\u3001test \u306e\u5185\u5bb9\u3068\u5168\u304f\u540c\u3058\u5185\u5bb9\u3067\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3092\u4f5c\u308a\u76f4\u3059\u5f62\u306b\u306a\u308b\u306e\u3067\u3001<br \/>\n\u3053\u308c\u3060\u3051\u3067\u30b3\u30d4\u30fc\u304c\u3067\u304d\u3066\u3057\u307e\u3046\u306e\u3067\u3059\u3002<\/p>\n<p>\u3061\u306a\u307f\u306b\u3001\u30b9\u30d7\u30ec\u30c3\u30c9\u69cb\u6587\u306f\u5358\u7d14\u306b\u305d\u306e\u5834\u306b\u5185\u5bb9\u3092\u5c55\u958b\u3057\u3066\u3044\u308b\u3060\u3051\u306a\u306e\u3067\u3001<br \/>\n\u5024\u306e\u8ffd\u52a0\u3082\u3067\u304d\u307e\u3059\u3002<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nvar test = { a: 10 };\nvar test_copy = { ...test, b: 20 };\n<\/pre>\n<p>\u3053\u3093\u306a\u611f\u3058\u3067\u66f8\u3051\u3070\u3001 <code>{ a: 10, b: 20 }<\/code> \u3068\u3044\u3046\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u304c\u4f5c\u308c\u308b\u306e\u3067\u3059\u306d\u3002<\/p>\n<p>\u3082\u3061\u308d\u3093\u3001\u30b9\u30d7\u30ec\u30c3\u30c9\u69cb\u6587\u3092\u4f55\u500b\u3082\u66f8\u3044\u3066\u3082\u826f\u3044\u306e\u3067<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nvar test1 = { a: 10 };\nvar test2 = { b: 20 };\nvar test_copy = { ...test1, ...test2 };\n<\/pre>\n<p>\u3053\u3093\u306a\u306e\u3082 OK\u3002<\/p>\n<h1>\u914d\u5217\u306e\u30b3\u30d4\u30fc\u3082\u304a\u3093\u306a\u3058\u611f\u3058\u3067\u3002<\/h1>\n<p>\u914d\u5217\u306e\u30b3\u30d4\u30fc\u3082\u3001\u540c\u3058\u3088\u3046\u306b\u30b9\u30d7\u30ec\u30c3\u30c9\u69cb\u6587\u3092\u4f7f\u3063\u3066\u66f8\u304f\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nvar test = &#x5B;10, 20, 30];\nvar test_copy = &#x5B; ...test ];\n<\/pre>\n<p>\u3053\u306e\u3088\u3046\u306b\u66f8\u304f\u3060\u3051\u3067\u3001\u7c21\u5358\u306b\u914d\u5217\u3082\u30b3\u30d4\u30fc\u3067\u304d\u308b\u306e\u3067\u3059\u306d\u3002<br \/>\n\u3053\u308c\u3082\u3001\u914d\u5217\u306e\u7d50\u5408\u306a\u3069\u3067\u3082\u3088\u304f\u3064\u304b\u308b\u5834\u9762\u304c\u3042\u308a\u307e\u3059\u3002<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nvar test1 = &#x5B;10, 20, 30];\nvar test2 = &#x5B;40, 50];\nvar test_copy = &#x5B; ...test1, ...test2 ];\n<\/pre>\n<p>\u3053\u3093\u306a\u611f\u3058\u3067\u66f8\u304f\u3060\u3051\u3067\u7c21\u5358\u306b\u7d50\u5408\u3067\u304d\u3061\u3083\u3044\u307e\u3059\u3002<\/p>\n<p>\u3082\u3046\u3061\u3087\u3063\u3068\u8a00\u3046\u3068\u3053\u3093\u306a\u3053\u3068\u3082\u3002<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nvar test = &#x5B;10, 20];\n\nvar test_func = function (a, b) {\n  console.log(a + b);\n};\n\ntest_func(...test);\n\/\/ 30 \u3068\u8868\u793a\u3055\u308c\u308b\n<\/pre>\n<p>\u95a2\u6570\u306e\u5f15\u6570\u3067\u30b9\u30d7\u30ec\u30c3\u30c9\u69cb\u6587\u3092\u4f7f\u3046\u3053\u3068\u3067\u3001\u914d\u5217\u304c\u5c55\u958b\u3055\u308c\u3001<br \/>\na \u306b\u306f 10, b \u306b\u306f 20 \u304c\u5165\u308a\u307e\u3059\u3002<\/p>\n<p>\u3053\u308c\u306f\u3042\u307e\u308a\u4f7f\u3044\u3069\u3053\u308d\u306f\u306a\u3044\u3067\u3059\u304c\u3001<br \/>\n\u5f15\u6570\u304c\u591a\u3044\u95a2\u6570\u3092\u4f7f\u3046\u5834\u5408\u306f\u4f7f\u3063\u3066\u307f\u308b\u3068\u4fbf\u5229\u304b\u3082\u3057\u308c\u306a\u3044\u3067\u3059\u306d\u3002<\/p>\n<h1>\u30b9\u30d7\u30ec\u30c3\u30c9\u69cb\u6587\u3001\u4f7f\u3063\u3066\u307f\u3088\u3046\uff01<\/h1>\n<p>\u30b9\u30d7\u30ec\u30c3\u30c9\u69cb\u6587\u306f ES6 \u304b\u3089\u8ffd\u52a0\u3055\u308c\u305f\u3082\u306e\u3067\u3001\u3042\u307e\u308a\u306a\u3058\u307f\u304c\u306a\u3044\u66f8\u304d\u65b9\u3067\u306f\u3042\u308a\u307e\u3059\u3002<br \/>\n\u304c\u3001\u4e00\u5ea6\u4f7f\u3063\u3066\u3057\u307e\u3046\u3068\u305d\u306e\u4fbf\u5229\u3055\u306b\u9a5a\u304b\u308c\u308b\u306e\u3067\u306f\u306a\u3044\u3067\u3057\u3087\u3046\u304b\u3002<\/p>\n<p>\u7d30\u304b\u3044\u3068\u3053\u308d\u3067\u3059\u304c\u3001\u7c21\u5358\u306b\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306e\u30b3\u30d4\u30fc\u306a\u3069\u304c\u3067\u304d\u308b\u30b9\u30d7\u30ec\u30c3\u30c9\u69cb\u6587\u3001<br \/>\n\u662f\u975e\u4f7f\u3063\u3066\u307f\u3066\u304f\u3060\u3055\u3044\u306d\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3084\u914d\u5217\u306e\u30b3\u30d4\u30fc\u3063\u3066\u3069\u3046\u3084\u3063\u3066\u66f8\u304d\u307e\u3059\u304b\uff1f \u7686\u3055\u3093 JavaScript \u66f8\u3044\u3066\u307e\u3059\u304b\uff1f JavaScript \u3092\u30ac\u30c3\u30c4\u30ea\u66f8\u3044\u3066\u3044\u308b\u3068\u3001\u305f\u307e\u306b\u5fc5\u8981\u306b\u306a\u308b\u306e\u304c \u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3084\u914d\u5217\u306e\u30b3\u30d4\u30fc\u3002 \u307f\u306a\u3055\u3093\u3069\u3046\u3084\u3063\u3066\u307e\u3059 [&hellip;]<\/p>\n","protected":false},"author":15,"featured_media":15091,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[10],"tags":[45],"class_list":["post-15088","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-tech","tag-javascript"],"jetpack_featured_media_url":"https:\/\/www.agent-grow.com\/self20percent\/wp-content\/uploads\/2019\/09\/850c7612116999490846136e772ab7fd-1.png","jetpack_shortlink":"https:\/\/wp.me\/p7Bq4F-3Vm","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.agent-grow.com\/self20percent\/wp-json\/wp\/v2\/posts\/15088","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.agent-grow.com\/self20percent\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.agent-grow.com\/self20percent\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.agent-grow.com\/self20percent\/wp-json\/wp\/v2\/users\/15"}],"replies":[{"embeddable":true,"href":"https:\/\/www.agent-grow.com\/self20percent\/wp-json\/wp\/v2\/comments?post=15088"}],"version-history":[{"count":0,"href":"https:\/\/www.agent-grow.com\/self20percent\/wp-json\/wp\/v2\/posts\/15088\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.agent-grow.com\/self20percent\/wp-json\/wp\/v2\/media\/15091"}],"wp:attachment":[{"href":"https:\/\/www.agent-grow.com\/self20percent\/wp-json\/wp\/v2\/media?parent=15088"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.agent-grow.com\/self20percent\/wp-json\/wp\/v2\/categories?post=15088"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.agent-grow.com\/self20percent\/wp-json\/wp\/v2\/tags?post=15088"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}