Use function reference value passing in JavaScript

Description

The following code shows how to use function reference value passing.

Example


<!DOCTYPE html>
<html>
<head>
<script type="text/javascript">
function setName(obj) {<!--   w  ww .  j  av a2 s . co  m-->
obj.name = "JavaScript";
}
var person = new Object();
setName(person);
document.writeln(person.name); //"JavaScript"
</script>
</head>
<body>
</body>
</html>

Click to view the demo

The code above generates the following result.

Use function reference value passing in JavaScript