<p>Js 函数定义的三种方式:</p>
<br>
<p>方式一:function</p>
<script type="text/javascript">
    function add(num1, num2){
        return num1+num2+200;
    }
    var sum = add(122, 10000);
    window.document.write(sum);
</script>
<br>
<p>方式二:new Function <font color="red">(注:new Function这种方式用的比较少)</font></p>
<script type="text/javascript">
    var add=new Function("num", "return num+200");    // new Function这种方式用的比较少
    var sum=add(122);
    window.document.write(sum);
</script>

<br>
<p>方式三:var add=function(){}</p>
<script type="text/javascript">
    var add = function(num1, num2){return num1+num2+200;};
    var sum=add(122,300);
    window.document.write(sum);
</script>

 

相关文章:

  • 2022-12-23
  • 2021-09-01
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-17
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案