Anonymous
Как присвоить значения аргументам Destructuring Function?
Сообщение
Anonymous » 04 июн 2025, 21:47
У меня есть функция, которая принимает аргументы разрушенных (так что я могу отправлять именованные параметры из вызывающего кода): < /p>
Код: Выделить всё
function createAccount({Param1, Param2, Param3, Param4}){
for (let [Key, Value] of Object.entries(arguments[0])) {
console.log(`Before transform ${Key}: ${Value}`);
// Param1: A, Param2: B, Param3: C, Param4: D
}
// Here I need to loop over the arguments and transform their values
let count = 0
for (let [Key, Value] of Object.entries(arguments[0])) {
arguments[0][Key] = count + 1;
count += 1;
}
for (let [Key, Value] of Object.entries(arguments[0])) {
console.log(`after transform ${Key}: ${Value}`);
// Param1: 1, Param2: 2, Param3: 3, Param4: 4
}
console.log(Param1, Param2, Param3, Param4);
// Param1: A, Param2: B, Param3: C, Param4: D
//It hasn't transformed?!
}
createAccount({Param1: 'A', Param2: 'B', Param3: 'C', Param4: 'D'});
Я надеюсь, что код является самоочевидным, но в основном я пытаюсь преобразовать значения аргументов из A, B, C, D Взативно в 1, 2, 3, 4
Подробнее здесь:
https://stackoverflow.com/questions/796 ... -arguments
1749062841
Anonymous
У меня есть функция, которая принимает аргументы разрушенных (так что я могу отправлять именованные параметры из вызывающего кода): < /p> [code]function createAccount({Param1, Param2, Param3, Param4}){ for (let [Key, Value] of Object.entries(arguments[0])) { console.log(`Before transform ${Key}: ${Value}`); // Param1: A, Param2: B, Param3: C, Param4: D } // Here I need to loop over the arguments and transform their values let count = 0 for (let [Key, Value] of Object.entries(arguments[0])) { arguments[0][Key] = count + 1; count += 1; } for (let [Key, Value] of Object.entries(arguments[0])) { console.log(`after transform ${Key}: ${Value}`); // Param1: 1, Param2: 2, Param3: 3, Param4: 4 } console.log(Param1, Param2, Param3, Param4); // Param1: A, Param2: B, Param3: C, Param4: D //It hasn't transformed?! } createAccount({Param1: 'A', Param2: 'B', Param3: 'C', Param4: 'D'}); [/code] Я надеюсь, что код является самоочевидным, но в основном я пытаюсь преобразовать значения аргументов из A, B, C, D Взативно в 1, 2, 3, 4 Подробнее здесь: [url]https://stackoverflow.com/questions/79653230/how-to-reassign-values-to-destructured-function-arguments[/url]