zoukankan      html  css  js  c++  java
  • 定义与参数_函数声明示例

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <title>模块模式</title>
        <script src="../unitl/test.js"></script>
        <style>
            #results li.pass {color:green;}
            #results li.fail {color:red;}
        </style>
    </head>
    <body>
    
        <ul id="results"></ul>
    
        
    </body>
    
    
    <script>
    
        //在全局代码中定义samurai函数。
        function samurai() {
    
            return "samurai here";
    
        }
    
        // 在全局代码中定义ninja函数
        function ninja() {
    
            //在ninja函数内定义hiddenNinja函数。
            function hiddenNinja() {
    
                return "ninja here";
            }
    
            return hiddenNinja();
    
        }
    
        report(ninja())
        
    
    
    </script>
    </html>
    

    这个函数比较特别,一个函数被定义在另一个函数之中!

      // 在全局代码中定义ninja函数
        function ninja() {
    
            //在ninja函数内定义hiddenNinja函数。
            function hiddenNinja() {
    
                return "ninja here";
            }
    
            return hiddenNinja();
    
        }
    
    

    在javascript中,这是一种非常通用的的使用方式。用它举例子值为了再次javascript中函数的重要性。

  • 相关阅读:
    Ruby 操作 Mysql (2)
    有关SQL模糊查询【转载】
    vim命令行大全【转载】
    Ruby连接MySQL
    c# 操作mysql
    sublime 3 快捷键大全
    VS2010快捷键大全
    [使用Xpath对XML进行模糊查询]
    vim永久显示行号
    Ubuntu16.04LTS安装flash player
  • 原文地址:https://www.cnblogs.com/jamal/p/14103842.html
Copyright © 2011-2022 走看看