Похожие чаты

Hi all, I'm learning about reference types in JS. I

now know passing {} object is pass by reference, and if I change a property, this property will be changed everywhere else for the same object. so this what happen when I try this:
var someFunc = (val) => val.Hello = 'Hello World!';
var obj1 = {Hello:'Will Change'};
someFunc(obj1);
Console.Log(obj1.Hello); // output: Hello World!
Now I have a case where I want to update an object values without using constructor and deconstructor, because if I do so, I'll lose that reference.
So I can't use this:
var obj2 = { Hello: 'Another Hello', Other: 'This is another text' };
obj1 = {...obj1, ...obj2};
How can iterate through obj2 properties and assign them to obj1 without losing reference?

6 ответов

27 просмотров
Adnan-Al_Beda Автор вопроса

I did this solution in a different place. Still need to assign these values dynamically. I'm using typescript, so I can confirm that they at least have the same properties, would this help in any way?

Object.assign(obj1, obj2)

Banana
Object.assign(obj1, obj2)

what they want: given a ={} b= {f:10} copy b to a by reference such that if later they do b.f = 800, it updates a.f also

Adnan-Al_Beda Автор вопроса
Perlik Yubenji
what they want: given a ={} b= {f:10} copy b to ...

I don't really care about b, I just need a to be updated when I consume b.

Похожие вопросы

Обсуждают сегодня

Господа, а что сейчас вообще с рынком труда на делфи происходит? Какова ситуация?
Rꙮman Yankꙮvsky
29
А вообще, что может смущать в самой Julia - бы сказал, что нет единого стандартного подхода по многим моментам, поэтому многое выглядит как "хаки" и произвол. Короче говоря, с...
Viktor G.
2
@Benzenoid can you tell me the easiest, and safest way to bu.y HEX now?
Živa Žena
20
This is a question from my wife who make a fortune with memes 😂😂 About the Migration and Tokens: 1. How will the old tokens be migrated to the new $LGCYX network? What is th...
🍿 °anton°
2
30500 за редактор? )
Владимир
47
а через ESC-код ?
Alexey Kulakov
29
What is the Dex situation? Agora team started with the Pnetwork for their dex which helped them both with integration. It’s completed but as you can see from the Pnetwork ann...
Ben
1
Гайс, вопрос для разносторонее развитых: читаю стрим с юарта, нада выделять с него фреймы с определенной структурой, если ли чо готовое, или долбаться с ринг буффером? нада у...
Vitaly
9
Anyone knows where there are some instructions or discort about failed bridge transactions ?
Jochem
21
@lozuk how do I get my phex copies of my ehex from a atomic wallet, to move to my rabby?
Justfrontin 👀
11
Карта сайта