■プログラムから新しく関数を作成したい
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Script-Type" content="text/javascript">
<meta http-equiv="Content-Type" content="text/html; charset=Shift_JIS">
<meta http-equiv="Content-Style-Type" content="text/css">
<title>プログラムから新しく関数を作成したい</title>
<body>
<p>■プログラムから新しく関数を作成したい</p>
<script type="text/JavaScript">
<!--
calc = new Function("i","j","return i+j");
document.write("<p>新しく作成した関数=「calc = new Function("i","j","return i+j")」<br>");
document.write("calc(10,20)の実行結果 = "+calc(10,20)+"</p>");
document.write("<hr>");
document.write("<p>新しく作成した関数=「bgc = new Function("color","document.bgColor=color")」</p>");
bgc = new Function("color","document.bgColor=color");
// -->
</script>
<form name="fm1">
<p><input type="button" value="bgc("green")の実行" onclick="bgc('green')"></p>
</form>
</body>
</html>