zoukankan      html  css  js  c++  java
  • js将方法作为参数调用

    <!DOCTYPE html>
    <html>
    <head>
        <meta http-equiv="content-type" content="text/html; charset=utf-8" />
        <title>js调用</title>    
        <script src="cssjs/jquery.js" type="text/javascript"></script>
        <script type="text/javascript">
            $().ready(function () {
                $.dialog = function (settings) {
                    if ($.isFunction(settings.okCallback)) {
                        if (settings.height == null) {
                            if (settings.okCallback.apply() != false) {
                                alert("1");
                            }
                        } else {
                            
                            if (settings.okCallback.call(this, settings.height) != false) {
                                alert("2");
                            }
                            
                            /*
                            if (settings.okCallback.apply(this, arguments) != false) {
                                alert("2");
                            }
                            */
                        }
                    }
                }
            });        
        </script>
        <script type="text/javascript">
            $(function () {
                $.dialog({
                    okCallback: print,
                    height: {data:"你好"}
                });
            });
        function print(ee1) {
            alert("print(ee1)");
            
            alert(ee1.data);
            
            /*
            alert(ee1.height.data);
            */
        }
        /*
        function print(a, b, c, d) {
        alert(a + b + c + d);
        }
        function example(a, b, c, d) {
        //用call方式借用print,参数显式打散传递
        print.call(this, a, b, c, d);
        //用apply方式借用print, 参数作为一个数组传递,
        //这里直接用JavaScript方法内本身有的arguments数组
        print.apply(this, arguments);
        //或者封装成数组
        print.apply(this, [a, b, c, d]);
        }
        //下面将显示"背光脚本"
        example("背", "光", "脚", "本"); 
        */
        </script>
    </head>
    <body>
        
    </body>
    </html>
  • 相关阅读:
    [pycharm]远程调试服务器项目
    [Linux]防火墙关闭与开启
    [Linux]安装pyenv
    [Linux]ubuntu安装基本流程
    [python]html格式转md格式
    [python]目录及文件操作
    [Linux]安装node.js
    Linux基础
    爬虫基础(3)
    爬虫基础(2)
  • 原文地址:https://www.cnblogs.com/daixingqing/p/3342838.html
Copyright © 2011-2022 走看看