JavaScript Tip: Understanding the Mutability of JavaScript Objects

preview_player
Показать описание
JavaScript objects are mutable; able to change. In order to use objects effectively, it is important to understand how they behave because of this characteristic. We will look at a couple of examples to show what can occur if you ignore that objects can mutate.
For more resources on JavaScript:

Interested in some of our courses:

Tutorials referred to in this video:
Рекомендации по теме
Комментарии
Автор

Watched it repeatedly several times, then come to know the creation of a function has that much impact.

AussLyf
Автор

this video does a good job in explaining "pass by reference".

johnnygarces
Автор

Hello sir! I'm very glad about this video. But I have a question, why does "incBy2()" get called even before "incBy1()" finishes executing? Do both the lines execute at the same time thereby changing the value of "obj.increment" at the same time? Thanks a lot!

mahaan
Автор

You could of at the end of the video, put the solution to fix the issue. I got what you was referring to, but you only pointed out the problem, not how to fix the problem.

Defender
Автор

Hi. I have a question. In that example, why would someone write the line "obj.increment = val;" outside the return function. It seems weird enough, I mean, by doing so, that object value changes when the variable is declared unwantedly as you said and that causes the issue. Cloning solution aside, even if the case someone want the function variable change the value when excuted, it still looks kind of wrong because you can just write that line inside the return function so that the value changes only when the function designated to the variance get actually executed. Maybe you just made it up that way just for explaining it?
I am assuming maybe there is a reason for that. Like, there is a similar javascript pattern that makes people write like that and there they makes this kind of mistakes.. or something like that. Just would like to know. Thanks.

bordertone_
Автор

what the keyboard and switches do you use? CD nice sound

romazahrypa