Convert function to string in JavaScript

Description

The following code shows how to convert function to string.

Example


<!--from   ww w  . j a v a 2 s .c  om-->
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript">

var f = function sayColor(){
document.writeln("asdf");
}
document.writeln(f.toLocaleString());

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

Click to view the demo

The code above generates the following result.

Convert function to string in JavaScript