JavaScript Tip: Understanding the Mutability of JavaScript Objects

Поделиться
HTML-код
  • Опубликовано: 10 сен 2024

Комментарии • 18

  • @AussLyf
    @AussLyf 4 года назад +1

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

  • @johnnygarces2216
    @johnnygarces2216 4 года назад +2

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

    • @edgarmalik8587
      @edgarmalik8587 3 года назад

      @Conrad Maddox Yup, I have been using flixzone} for since december myself :)

  • @mahaan6218
    @mahaan6218 4 года назад +1

    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!

    • @AllThingsJavaScript
      @AllThingsJavaScript  4 года назад +3

      incBy2 doesn't get called before incBy1. The creation of that function gets called before we call the function creating incBy1. Because the increment by 2 function is created it changes the increment value to 2 because all variables are pointing to the same object. Does that help?

    • @mahaan6218
      @mahaan6218 4 года назад

      @@AllThingsJavaScript Hi. Thanks for the reply.
      I understand it now. BTW, great tutorial :)

  • @jimmyciaston7733
    @jimmyciaston7733 6 лет назад

    Great video and explanation !

  • @Defender2516
    @Defender2516 6 лет назад +2

    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.

    • @AllThingsJavaScript
      @AllThingsJavaScript  6 лет назад

      There are several different things that can be done that can be covered in other tutorials. And to be fair the "problem" is caused by how we structure our code not necessarily a deficiency in JavaScript.

    • @AllThingsJavaScript
      @AllThingsJavaScript  6 лет назад

      Here is a link to a tutorial that provides a solution: ruclips.net/video/3ImrKR3OkHs/видео.html

  • @ManontheBroadcast
    @ManontheBroadcast 6 лет назад

    Great ... very helpful !

  • @oghenefokethompson7407
    @oghenefokethompson7407 4 года назад

    This was really helpful thank sir.

  • @bordertone_5138
    @bordertone_5138 4 года назад

    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.

    • @AllThingsJavaScript
      @AllThingsJavaScript  4 года назад

      It is quite common to do statements before you return a value from a function. So that wouldn't be out of the ordinary. And changing an object is not out of the ordinary either. But it is important to understand the implications. Those that subscribe the a functional approach would of course avoid making a change like that. Does that help?

    • @bordertone_5138
      @bordertone_5138 4 года назад

      @@AllThingsJavaScript I reviewed it again and I think I understand what was intended by that, in case of one want to make it reusable by simply calling the function with parameter I guess. It must have looked more familiar to me if I have more experience on the language. Thank you for the quick answer.

  • @utmostcreator
    @utmostcreator 4 года назад

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