{"id":299106,"date":"2020-02-22T21:00:08","date_gmt":"2020-02-22T21:00:08","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=299106"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=299106","title":{"rendered":"7 \u0442\u0440\u044e\u043a\u043e\u0432 \u0441 Rest \u0438 Spread \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u0430\u043c\u0438 \u043f\u0440\u0438 \u0440\u0430\u0431\u043e\u0442\u0435 c JS \u043e\u0431\u044a\u0435\u043a\u0442\u0430\u043c\u0438"},"content":{"rendered":"\n<div class=\"post__text post__text-html\" id=\"post-content-body\" data-io-article-url=\"https:\/\/habr.com\/ru\/post\/489550\/\">\u041f\u0440\u0438\u0432\u0435\u0442, \u0425\u0430\u0431\u0440! \u041f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u044e \u0432\u0430\u0448\u0435\u043c\u0443 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u044e \u043f\u0435\u0440\u0435\u0432\u043e\u0434 \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/blog.bitsrc.io\/6-tricks-with-resting-and-spreading-javascript-objects-68d585bdc83\">\u00ab7 Tricks with Resting and Spreading JavaScript Objects\u00bb<\/a> \u0430\u0432\u0442\u043e\u0440\u0430 Joel Thoms.<\/p>\n<p>  \u0412\u0441\u0435\u043c \u043f\u0440\u0438\u0432\u0435\u0442, \u043d\u0430 \u0434\u043d\u044f\u0445 \u043a\u043e\u043b\u043b\u0435\u0433\u0430 \u043f\u043e \u0440\u0430\u0431\u043e\u0442\u0435 \u0441\u043a\u0438\u043d\u0443\u043b \u043c\u043d\u0435 \u0441\u0441\u044b\u043b\u043a\u0443 \u043d\u0430 \u0441\u0442\u0430\u0442\u044c\u044e \u043d\u0430 \u0430\u043d\u0433\u043b\u0438\u0439\u0441\u043a\u043e\u043c \u044f\u0437\u044b\u043a\u0435 \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u043f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u044f\u044e\u0442\u0441\u044f \u0440\u0430\u0437\u043d\u044b\u0435 \u043c\u0435\u0442\u043e\u0434\u044b \u0440\u0430\u0431\u043e\u0442\u044b \u0441 rest \u0438 spread \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u0430\u043c\u0438. \u041e\u043d\u0430 \u043e\u043a\u0430\u0437\u0430\u043b\u0430\u0441\u044c \u043c\u043d\u0435 \u043f\u043e\u043b\u0435\u0437\u043d\u0430 \u0438 \u044f \u0440\u0435\u0448\u0438\u043b \u0435\u0451 \u043f\u0435\u0440\u0435\u0432\u0435\u0441\u0442\u0438. \u0418\u0442\u0430\u043a, \u043d\u0430\u0447\u043d\u0435\u043c.<\/p>\n<p>  <img decoding=\"async\" src=\"https:\/\/miro.medium.com\/max\/2000\/1*ii1ZQQKmpmEFOFCY5VkTxA.jpeg\" alt=\"image\"\/><br \/>  <a name=\"habracut\"><\/a><br \/>  Rest \u0438 Spread \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u044b \u043c\u043e\u0433\u0443\u0442 \u0431\u044b\u0442\u044c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u044b \u043d\u0435 \u0442\u043e\u043b\u044c\u043a\u043e \u0434\u043b\u044f \u043e\u0431\u044a\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u044f \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u043e\u0432 \u0432 \u043c\u0430\u0441\u0441\u0438\u0432 \u0438 \u043e\u0431\u044a\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u044f \u043c\u0430\u0441\u0441\u0438\u0432\u043e\u0432.<\/p>\n<p>  \u0412 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u0432\u044b \u043d\u0430\u0439\u0434\u0435\u0442\u0435 7 \u043d\u0430\u0438\u043c\u0435\u043d\u0435\u0435 \u0438\u0437\u0432\u0435\u0441\u0442\u043d\u044b\u0445 \u0442\u0440\u044e\u043a\u043e\u0432 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f rest \u0438 spread \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u043e\u0432.<\/p>\n<h4>1. \u0414\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0441\u0432\u043e\u0439\u0441\u0442\u0432 <\/h4>\n<p>  \u041a\u043b\u043e\u043d\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u043e\u0431\u044a\u0435\u043a\u0442\u0430 \u043e\u0434\u043d\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u044f \u043a \u043d\u043e\u0432\u043e\u043c\u0443 \u043e\u0431\u044a\u0435\u043a\u0442\u0443 \u043a \u043a\u043b\u043e\u043d\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u043c\u0443 \u043e\u0431\u044a\u0435\u043a\u0442\u0443.<br \/>  \u0412 \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u0441\u043d\u0438\u0437\u0443 \u043c\u044b \u043a\u043b\u043e\u043d\u0438\u0440\u0443\u0435\u043c \u043e\u0431\u044a\u0435\u043a\u0442 <b>user <\/b>\u0438 \u0432 \u043a\u043b\u043e\u043d\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0439 \u043e\u0431\u044a\u0435\u043a\u0442 <b>userWithPass <\/b>\u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u043e <b>password<\/b>.<\/p>\n<pre><code class=\"javascript\">const user = { id: 100, name: 'Howard Moon'} const userWithPass = { ...user, password: 'Password!' }  user \/\/=&gt; { id: 100, name: 'Howard Moon' } userWithPass \/\/=&gt; { id: 100, name: 'Howard Moon', password: 'Password!' }<\/code><\/pre>\n<p>  <\/p>\n<h4>2. \u0421\u043b\u0438\u044f\u043d\u0438\u0435 \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432<\/h4>\n<p>  \u041e\u0431\u044a\u043a\u0442\u044b <b>part1 <\/b>\u0438 <b>part2<\/b> \u043c\u0435\u0440\u0436\u0430\u0442\u0441\u044f \u0432 \u043e\u0431\u044a\u0435\u043a\u0442 <b>user1<\/b><\/p>\n<pre><code class=\"javascript\">const part1 = { id: 100, name: 'Howard Moon' } const part2 = { id: 100, password: 'Password!' }  const user1 = { ...part1, ...part2 } \/\/=&gt; { id: 100, name: 'Howard Moon', password: 'Password!' }<\/code><\/pre>\n<p>  \u0422\u0430\u043a-\u0436\u0435 \u043e\u0431\u044a\u0435\u043a\u0442\u044b \u043c\u043e\u0433\u0443\u0442 \u0431\u044b\u0442\u044c \u0441\u043c\u0435\u0440\u0436\u0435\u043d\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u0442\u0430\u043a\u043e\u0439 \u0441\u0438\u043d\u0442\u0430\u043a\u0441\u0438\u0441.<\/p>\n<pre><code class=\"javascript\">const partial = { id: 100, name: 'Howard Moon' } const user = { ...partial, id: 100, password: 'Password!' }  user \/\/=&gt; { id: 100, name: 'Howard Moon', password: 'Password!' }<\/code><\/pre>\n<p>  <\/p>\n<h4>3. \u0423\u0434\u0430\u043b\u0435\u043d\u0438\u0435 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430 \u0438\u0437 \u043e\u0431\u044a\u0435\u043a\u0442\u0430<\/h4>\n<p>  \u0421\u0432\u043e\u0439\u0441\u0442\u0432\u0430 \u0438\u0437 \u043e\u0431\u044a\u0435\u043a\u0442\u0430 \u043c\u043e\u0433\u0443\u0442 \u0431\u044b\u0442\u044c \u0443\u0434\u0430\u043b\u0435\u043d\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u043a\u043e\u043c\u0431\u0438\u043d\u0430\u0446\u0438\u044e \u0434\u0435\u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0438\u0437\u0430\u0446\u0438\u0438 \u0438 rest \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u0430. \u0412 \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u043d\u0438\u0436\u0435 \u0434\u0435\u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0438\u0437\u0443\u0435\u043c \u043e\u0431\u044a\u0435\u043a\u0442 <b>rest<\/b> \u0438 \u0443\u0431\u0438\u0440\u0430\u0435\u043c \u0438\u0437 \u043d\u0435\u0433\u043e \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u043e <b>password<\/b>.<\/p>\n<pre><code class=\"javascript\">const noPassword = ({ password, ...rest }) =&gt; rest const user = {   id: 100,   name: 'Howard Moon',   password: 'Password!' }  noPassword(user) \/\/=&gt; { id: 100, name: 'Howard moon' }<\/code><\/pre>\n<p>  <\/p>\n<h4>4. \u0414\u0438\u043d\u0430\u043c\u0438\u0447\u0435\u0441\u043a\u043e\u0435 \u0443\u0434\u0430\u043b\u0435\u043d\u0438\u0435 \u0441\u0432\u043e\u0439\u0441\u0442\u0432<\/h4>\n<p>  \u0412 \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u0441\u043d\u0438\u0437\u0443 \u0444\u0443\u043d\u043a\u0446\u0438\u044f <b>removeProperty<\/b> \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 <b>prop<\/b> \u043a\u0430\u043a \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442. \u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u043f\u0435\u0440\u0435\u0434\u0430\u043d\u043d\u043e\u0435 \u0432 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u0435 \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430 \u043c\u044b \u0434\u0438\u043d\u0430\u043c\u0438\u0447\u0435\u0441\u043a\u0438 \u0438\u0441\u043a\u043b\u044e\u0447\u0430\u0435\u043c \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u043e \u0438\u0437 \u043a\u043b\u043e\u043d\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u0433\u043e \u043e\u0431\u044a\u0435\u043a\u0442\u0430.<\/p>\n<pre><code class=\"javascript\">const user1 = {   id: 100,   name: 'Howard Moon',   password: 'Password!' } const removeProperty = prop =&gt; ({ [prop]: _, ...rest }) =&gt; rest \/\/                     ----       ------ \/\/                          \\   \/ \/\/                dynamic destructuring  const removePassword = removeProperty('password') const removeId = removeProperty('id')  removePassword(user1) \/\/=&gt; { id: 100, name: 'Howard Moon' } removeId(user1) \/\/=&gt; { name: 'Howard Moon', password: 'Password!' }<\/code><\/pre>\n<p>  <\/p>\n<h4>5. \u041e\u0440\u0433\u0430\u043d\u0438\u0437\u0430\u0446\u0438\u044f \u0438\u043b\u0438 \u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u043a\u0430 \u0441\u0432\u043e\u0439\u0441\u0442\u0432 \u043f\u043e \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u044e<\/h4>\n<p>  \u0418\u043d\u043e\u0433\u0434\u0430 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430 \u0432 \u043e\u0431\u044a\u0435\u043a\u0442\u0435 \u0440\u0430\u0441\u043f\u043e\u043b\u0430\u0433\u0430\u044e\u0442\u0441\u044f \u043d\u0435 \u0432 \u0442\u043e\u043c \u043f\u043e\u0440\u044f\u0434\u043a\u0435 \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e. \u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0442\u0440\u044e\u043a\u043e\u0432 \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u043f\u0443\u0448\u0438\u0442\u044c \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430 \u0432 \u043d\u0430\u0447\u0430\u043b\u043e \u0441\u043f\u0438\u0441\u043a\u0430 \u0438\u043b\u0438 \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 \u0432 \u0441\u0435\u0440\u0435\u0434\u0438\u043d\u0443.<\/p>\n<pre><code class=\"javascript\">const user3 = {   password: 'Password!',   name: 'Naboo',   id: 300 }  const organize = object =&gt; ({ id: undefined, ...object }) \/\/                            ------------- \/\/                          \/ \/\/  move id to the first property  organize(user3) \/\/=&gt; { id: 300, password: 'Password!', name: 'Naboo' }<\/code><\/pre>\n<p>  \u0414\u043b\u044f \u0442\u043e\u0433\u043e \u0447\u0442\u043e-\u0431\u044b \u043f\u043e\u043c\u0435\u0441\u0442\u0438\u0442\u044c <b>password <\/b>\u0432 \u043a\u043e\u043d\u0435\u0446 \u0441\u043d\u0430\u0447\u0430\u043b\u0430 \u043d\u0443\u0436\u043d\u043e \u0434\u0435\u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043e\u0431\u044a\u0435\u043a\u0442 \u0438 \u0443\u0431\u0440\u0430\u0442\u044c <b>password<\/b>, \u0430 \u0437\u0430\u0442\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c spread \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440 \u0447\u0442\u043e-\u0431\u044b \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u0435\u0433\u043e.<\/p>\n<h4>6. \u0421\u0432\u043e\u0439\u0441\u0442\u0432\u0430 \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e<\/h4>\n<p>  \u0421\u0432\u043e\u0439\u0441\u0442\u0432\u0430 \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e \u044d\u0442\u043e \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430 \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0431\u0443\u0434\u0443\u0442 \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d\u044b \u0432 \u0442\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u0435\u0441\u043b\u0438 \u0438\u0445 \u043d\u0435\u0442 \u0432 \u043a\u043b\u043e\u043d\u0438\u0440\u0443\u0435\u043c\u043e\u043c \u043e\u0431\u044a\u0435\u043a\u0442\u0435.<\/p>\n<p>  \u0412 \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u0441\u043d\u0438\u0437\u0443 \u0432 \u043e\u0431\u044a\u0435\u043a\u0442\u0435 <b>user2 <\/b>\u043e\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u0443\u0435\u0442 \u043f\u043e\u043b\u0435 <b>quotes<\/b>. \u0424\u0443\u043d\u043a\u0446\u0438\u044f setDefaults \u0432 \u0441\u043b\u0443\u0447\u0430\u0435 \u043e\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u0438\u044f \u043f\u043e\u043b\u044f <b>quotes <\/b>\u0443\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u0442 \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e \u0435\u0433\u043e \u0441\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435\u043c <b>[]<\/b>.<\/p>\n<p>  \u041f\u043e\u0441\u043b\u0435 \u0432\u044b\u0437\u043e\u0432\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 <b>setDefaults(user2)<\/b> \u043e\u043d\u0430 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u043d\u0430\u043c \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u043e \u0441\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435\u043c <b>quotes: []<\/b><br \/>  \u041f\u0440\u0438 \u0432\u044b\u0437\u043e\u0432\u0435 <b>setDefaults(user4)<\/b> \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u043d\u0435 \u043c\u043e\u0434\u0438\u0444\u0438\u0446\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0442\u0430\u043a \u043a\u0430\u043a \u043e\u0431\u044a\u0435\u043a\u0442 <b>user4 <\/b>\u0443\u0436\u0435 \u0438\u043c\u0435\u0435\u0442 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u043e <b>quotes<\/b><\/p>\n<pre><code class=\"javascript\">const user2 = {   id: 200,   name: 'Vince Noir' }  const user4 = {   id: 400,   name: 'Bollo',   quotes: [&quot;I've got a bad feeling about this...&quot;] }  const setDefaults = ({ quotes = [], ...object}) =&gt;   ({ ...object, quotes })  setDefaults(user2) \/\/=&gt; { id: 200, name: 'Vince Noir', quotes: [] }  setDefaults(user4) \/\/=&gt; { \/\/=&gt;   id: 400, \/\/=&gt;   name: 'Bollo', \/\/=&gt;   quotes: [&quot;I've got a bad feeling about this...&quot;] \/\/=&gt; }<\/code><\/pre>\n<p>  \u0422\u0430\u043a-\u0436\u0435 \u044d\u0442\u043e \u043c\u043e\u0436\u043d\u043e \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u0442\u0430\u043a \u0435\u0441\u043b\u0438 \u0432\u044b \u0445\u043e\u0442\u0438\u0442\u0435 \u0447\u0442\u043e-\u0431\u044b \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0430\u043b\u0438\u0441\u044c \u043f\u0435\u0440\u0432\u044b\u043c\u0438:<\/p>\n<pre><code class=\"javascript\">const setDefaults = ({ ...object}) =&gt; ({ quotes: [], ...object })<\/code><\/pre>\n<p>  <\/p>\n<h4>7. \u041f\u0435\u0440\u0435\u0438\u043c\u0435\u043d\u043e\u0432\u0430\u043d\u0438\u0435 \u0441\u0432\u043e\u0439\u0441\u0442\u0432<\/h4>\n<p>  \u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u0442\u0440\u044e\u043a\u0438 \u0441\u0432\u0435\u0440\u0445\u0443 \u043c\u044b \u0442\u0430\u043a-\u0436\u0435 \u043c\u043e\u0436\u0435\u043c \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043f\u0435\u0440\u0435\u0438\u043c\u0435\u043d\u0443\u0435\u0442 \u043d\u0430\u043c \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430 \u043e\u0431\u044a\u0435\u043a\u0442\u0430.<\/p>\n<p>  \u041f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u044c\u0442\u0435 \u0447\u0442\u043e \u0443 \u043d\u0430\u0441 \u0435\u0441\u0442\u044c \u043e\u0431\u044a\u0435\u043a\u0442 \u0441\u043e \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u043e\u043c ID \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u043d\u043e\u0435 \u0432 \u0432\u0435\u0440\u0445\u043d\u0435\u043c \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0435, \u0430 \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u043f\u0435\u0440\u0435\u0438\u043c\u0435\u043d\u043e\u0432\u0430\u0442\u044c \u0432 \u043d\u0438\u0436\u043d\u0438\u0439. \u041d\u0430\u0447\u043d\u0435\u043c \u0441 \u0443\u0434\u0430\u043b\u0435\u043d\u0438\u044f \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430 ID \u0438\u0437 \u043e\u0431\u044a\u0435\u043a\u0442\u0430. \u0417\u0430\u0442\u0435\u043c \u0434\u043e\u0431\u0430\u0432\u0438\u043c \u0435\u0433\u043e \u043d\u0430\u0437\u0430\u0434 \u0441 \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435\u043c id \u0432 \u0442\u043e \u0432\u0440\u0435\u043c\u044f \u043a\u0430\u043a \u043e\u0431\u044a\u0435\u043a\u0442 \u043a\u043b\u043e\u043d\u0438\u0440\u0443\u0435\u0442\u0441\u044f.<\/p>\n<pre><code class=\"javascript\">const renamed = ({ ID, ...object }) =&gt; ({ id: ID, ...object })  const user = {   ID: 500,   name: &quot;Bob Fossil&quot; }  renamed(user) \/\/=&gt; { id: 500, name: 'Bob Fossil' }<\/code><\/pre>\n<p>  <\/p>\n<h4>8. \u0411\u043e\u043d\u0443\u0441. \u0414\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430 \u0432 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u043e\u0442 \u0443\u0441\u043b\u043e\u0432\u0438\u044f<\/h4>\n<p>  \u0421\u043f\u0430\u0441\u0438\u0431\u043e <a href=\"http:\/\/twitter.com\/vinialbano\">@vinialbano<\/a> \u0437\u0430 \u0442\u043e \u0447\u0442\u043e \u043f\u043e\u043a\u0430\u0437\u0430\u043b \u0442\u0430\u043a\u043e\u0439 \u043c\u0435\u0442\u043e\u0434. \u0412 \u044d\u0442\u043e\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u043c\u044b \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u043f\u043e\u043b\u0435 <b>password <\/b>\u0442\u043e\u043b\u044c\u043a\u043e \u0435\u0441\u043b\u0438 <b>password == true<\/b>!<\/p>\n<pre><code class=\"javascript\">const user = { id: 100, name: 'Howard Moon' } const password = 'Password!' const userWithPassword = {   ...user,   id: 100,   ...(password && { password }) }  userWithPassword \/\/=&gt; { id: 100, name: 'Howard Moon', password: 'Password!' }<\/code><\/pre>\n<p>  <\/p>\n<h4>\u0412\u044b\u0432\u043e\u0434<\/h4>\n<p>  \u042f \u043f\u043e\u0441\u0442\u0430\u0440\u0430\u043b\u0441\u044f \u043f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u0438\u0442\u044c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043c\u0435\u043d\u0435\u0435 \u0438\u0437\u0432\u0435\u0441\u0442\u043d\u044b\u0445 \u043c\u0435\u0442\u043e\u0434\u043e\u0432 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f rest \u0438 spread \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u043e\u0432. \u0415\u0441\u043b\u0438 \u0432\u044b \u0437\u043d\u0430\u0435\u0442\u0435 \u0435\u0449\u0435 \u043a\u0430\u043a\u0438\u0435-\u043d\u0438\u0431\u0443\u0434\u044c \u043c\u0435\u0442\u043e\u0434\u044b \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043d\u0435 \u043f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u0435\u043d\u044b \u0432 \u0434\u0430\u043d\u043d\u043e\u043c \u0441\u043f\u0438\u0441\u043a\u0435 \u043f\u043e\u0436\u0430\u043b\u0443\u0439\u0441\u0442\u0430 \u043d\u0430\u043f\u0438\u0448\u0438\u0442\u0435 \u043e \u043d\u0438\u0445 \u0432 \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u044f\u0445. \u0415\u0441\u043b\u0438 \u0434\u0430\u043d\u043d\u0430\u044f \u0441\u0442\u0430\u0442\u044c\u044f \u0432\u0430\u043c \u043e\u043a\u0430\u0437\u0430\u043b\u0430\u0441\u044c \u043f\u043e\u043b\u0435\u0437\u043d\u0430 \u043f\u043e\u0436\u0430\u043b\u0443\u0439\u0441\u0442\u0430 \u0440\u0435\u043f\u043e\u0441\u0442\u043d\u0438\u0442\u0435 \u0435\u0451 \u0441\u0432\u043e\u0438\u043c \u0434\u0440\u0443\u0437\u044c\u044f\u043c \u0438 \u0437\u043d\u0430\u043a\u043e\u043c\u044b\u043c.<\/div>\n<p> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/post\/489550\/\"> https:\/\/habr.com\/ru\/post\/489550\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"\n<div class=\"post__text post__text-html\" id=\"post-content-body\" data-io-article-url=\"https:\/\/habr.com\/ru\/post\/489550\/\">\u041f\u0440\u0438\u0432\u0435\u0442, \u0425\u0430\u0431\u0440! \u041f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u044e \u0432\u0430\u0448\u0435\u043c\u0443 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u044e \u043f\u0435\u0440\u0435\u0432\u043e\u0434 \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/blog.bitsrc.io\/6-tricks-with-resting-and-spreading-javascript-objects-68d585bdc83\">\u00ab7 Tricks with Resting and Spreading JavaScript Objects\u00bb<\/a> \u0430\u0432\u0442\u043e\u0440\u0430 Joel Thoms.<\/p>\n<p>  \u0412\u0441\u0435\u043c \u043f\u0440\u0438\u0432\u0435\u0442, \u043d\u0430 \u0434\u043d\u044f\u0445 \u043a\u043e\u043b\u043b\u0435\u0433\u0430 \u043f\u043e \u0440\u0430\u0431\u043e\u0442\u0435 \u0441\u043a\u0438\u043d\u0443\u043b \u043c\u043d\u0435 \u0441\u0441\u044b\u043b\u043a\u0443 \u043d\u0430 \u0441\u0442\u0430\u0442\u044c\u044e \u043d\u0430 \u0430\u043d\u0433\u043b\u0438\u0439\u0441\u043a\u043e\u043c \u044f\u0437\u044b\u043a\u0435 \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u043f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u044f\u044e\u0442\u0441\u044f \u0440\u0430\u0437\u043d\u044b\u0435 \u043c\u0435\u0442\u043e\u0434\u044b \u0440\u0430\u0431\u043e\u0442\u044b \u0441 rest \u0438 spread \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u0430\u043c\u0438. \u041e\u043d\u0430 \u043e\u043a\u0430\u0437\u0430\u043b\u0430\u0441\u044c \u043c\u043d\u0435 \u043f\u043e\u043b\u0435\u0437\u043d\u0430 \u0438 \u044f \u0440\u0435\u0448\u0438\u043b \u0435\u0451 \u043f\u0435\u0440\u0435\u0432\u0435\u0441\u0442\u0438. \u0418\u0442\u0430\u043a, \u043d\u0430\u0447\u043d\u0435\u043c.<\/p>\n<p>  <img decoding=\"async\" src=\"https:\/\/miro.medium.com\/max\/2000\/1*ii1ZQQKmpmEFOFCY5VkTxA.jpeg\" alt=\"image\"\/>  <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-299106","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/299106","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=299106"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/299106\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=299106"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=299106"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=299106"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}