freeCodeCamp/guide/russian/certifications/javascript-algorithms-and-d.../es6/use-the-rest-operator-with-.../index.md

1.6 KiB
Raw Blame History

title localeTitle
Use the Rest Operator with Function Parameters Используйте оператор «Отдых» с параметрами функции

Используйте оператор «Отдых» с параметрами функции

Описание параметра Rest

Сеть разработчиков Mozilla

Оператор распространения по сравнению с параметром отдыха

Переполнение стека

Видео, объясняющее распространение и отдых

"Изображение

[### пример

Этот код

const product = (function() { 
    "use strict"; 
    return function product(n1, n2, n3) { 
        const args = [n1, n2, n3]; 
        return args.reduce((a, b) => a * b, 1); 
    }; 
 })(); 
 console.log(product(2, 4, 6));//48 

Может быть написано как таковое

const product = (function() { 
    "use strict"; 
    return function product(...n) { 
        return n.reduce((a, b) => a * b, 1); 
    }; 
 })(); 
 console.log(product(2, 4, 6));//48 

```](http://www.youtube.com/watch?feature=player_embedded&v=iLx4ma8ZqvQ
)