zoukankan      html  css  js  c++  java
  • js中声明函数的方法

    <!DOCTYPE html>
    <html lang="en">
    <head>
    <meta charset="UTF-8">
    <title></title>
    <script type="text/javascript">
    /**
    * 函数声明的三种方式
    *
    * 第一种 函数式声明
    * 第二种 表达式声明
    * 第三种 构造器声明
    *
    */

    function test(){}

    var a = test;
    var b = test();

    /**
    * 表达式声明
    *
    * 是在执行的时候才会解析相应的代码
    *
    */
    var c = function (){}

    var add = function (){
    var args = arguments;
    if(args.length===1){
    return args[0]+101;
    }else if(args.length === 2){
    return args[0]*args[1];
    }else{
    return "还没有被实现";
    }
    }
    var n1 = add(200);

    var n2 = add(200,200);
    var n3 = add(200,200,100);
    var n4 = add(200,200,200,500);
    console.log(n1);
    console.log(n2);
    console.log(n3);
    console.log(n4);

    var aa = new Function("a","b","c","alert(a+b+c)")
    </script>
    </head>
    <body>

    </body>
    </html>
  • 相关阅读:
    PHP自动加载(__autoload和spl_autoload_register)
    抽象工厂模式
    工厂方法模式
    简单工厂模式
    组合
    二叉树的层次遍历 II
    umask命令
    二叉树的所有路径
    CDN缓存的理解
    Js中RegExp对象
  • 原文地址:https://www.cnblogs.com/hwgok/p/5715486.html
Copyright © 2011-2022 走看看