Objects Are Passed by Reference

Video loading...

Join Drupalize.Me to watch this video

Join today and gain instant access to our entire video library.

Log in Sign up
  • 0:04
    Start another battle.
  • 0:08
    How about three cloak-shaped fighters against four RZ1 A-wing interceptors?
  • 0:16
    Behind the scenes, each ship has a strength.
  • 0:19
    The battle function uses this as the ship's health,
  • 0:23
    and as they battle each other, that health gets lower and lower
  • 0:27
    until one hits zero.
  • 0:29
    We need to add a new feature— after the battle,
  • 0:32
    display the final health of the battling ships.
  • 0:34
    One will be zero or negative, but how much health
  • 0:39
    did the other have left?
Loading ...

Objects Are Passed by Reference

Loading...

In this tutorial we're going to update some information in our ship object and see another way that objects are different from arrays—objects are always passed by reference. We need to add a new feature to our app so that after the battle we can display the final health of the battling ships. One will be zero or negative, but how much health did the other have left? Let's take a look at how we can update the ships to reflect their new health after a battle.

Downloads: 
Log in or sign up to download companion files.

Additional resources:
There are no resources for this video. If you believe there should be, please contact us.