Last active
August 29, 2015 14:01
-
-
Save kylejson/f64eac8472a8b49a4acf to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!doctype html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<title>Document</title> | |
</head> | |
<body> | |
<script type="text/javascript"> | |
function setHealth(obj) { | |
obj.hp = 100; | |
//obj = new Object(); | |
//obj.hp = 50; | |
} | |
var Player1 = new Object(); | |
setHealth(Player1); | |
alert("Avatar starts with HP: " + Player1.hp); //Player1's hp = 100; | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This always alerts "Avatar starts with HP: 100". If we leave lines 12-13 commented seems a lot like pass by reference, however in the case that they are uncommented we are reassigning obj which creates a new object in memory but it doesn't persist outside of the function scope. Pass by value?