Use function caller property in JavaScript

Description

The following code shows how to use function caller property.

Example


<!DOCTYPE html>
<html>
<head>
<script type="text/javascript">
function outer(){<!--  w  ww  .  j av  a  2s. co m-->
inner();
}
function inner(){
document.writeln(inner.caller);
}

outer(); //function outer(){ inner(); }
inner();//null


</script>
</head>
<body>
</body>
</html>

Click to view the demo

The code above generates the following result.

Use function caller property in JavaScript