数日前、外部スクリプトの実行途中で関数のコードを動的に変更することについて質問したところ、その概念に出くわすことは完全に忘れるように言われました。それがなぜなのか、よくわかりません。例を挙げましょう:
<script>
var display = function(msg)
{
alert(msg);
}
// Now, at the moment, the display() function
// is receiving a single parameter and alerting
// it to the user. I'm now going to use eval()
// to modify the display() function.
eval('display = ' + display.toString().replace('alert(', 'document.write('));
// Now, the display() function writes its parameter
// to the document as opposed to alerting it.
</script>
これはかなり些細な例だと思いますが、関数を動的に変更できることから派生できる用途がきっとあるはずです。それ自体が非常に便利です。