下面给出两段代码 执行结果一样,但是不同的意义在何处?
代码一:
- script language = "javascript">
- var square = new Function("x","y","var sum; sum = x*x+y*y;
- return sum;");
- alert(square(3,2));
- </script>
复制代码
代码二:
- <script language = "javascript">
- function square(x,y)
- {
- var sum ;
- sum = x*x + y*y;
- return sum;
- }
- alert(square(3,2));
- </script>
复制代码
这两段代码不同,但是就我看来,看不出第一种写法的意义何在啊? |