zoukankan      html  css  js  c++  java
  • 逆向思维开发

    javascript逆向思维开发

            //1.正常思维:对象定义好函数的执行过程,然后传递参数调用;
            //逆向思维:由对象定义好预调用参数的函数,函数的执行过程由提供的参数执行;
            var l = {};
            l.h = function (a) {    
                //执行参数a
                if (typeof (a) == "function") {
                    a(100);
                }
            }
            //调用:传参(函数)
            l.h(function (s) {
                console.log("args val = " + s); //结果:args val = 100
            });
    
            //对象替换
            var o = {};
            o.callFn = function (a) {
                fn.call(o, a);  //以o为基类,调用window.fn函数
            };
            function fn(s) {
                console.log("args val = " + s); 
            };
    
            //调用
            o.callFn(100); //结果:args val = 100
    

     asp.net利用委托实现javascript call函数

    protected void Page_Load(object sender, EventArgs e)
    {
        ///传递函数名进行委托方法绑定
        Call("英文", en); //结果:call en method,args:英文
        Call("中文", cn); //结果:绑定cn方法,参数:中文
    }
    /// <summary>
    /// 定义en方法
    /// </summary>
    public void en(string name)
    {
        Response.Write(string.Format("call en method,args:{0}", name));
    }
    /// <summary>
    /// 定义cn方法
    /// </summary>
    public void cn(string name)
    {
        Response.Write(string.Format("绑定cn方法,参数:{0}", name));
    }
    /// <summary>
    /// 定义委托,绑定函数
    /// </summary>
    private delegate void CallMethod(string name);
    /// <summary>
    /// 调用委托,绑定函数
    /// </summary>
    /// <param name="name">参数</param>
    /// <param name="method">函数名称</param>
    private static void Call(string name, CallMethod method)
    {
        method(name);
    }
    

      

  • 相关阅读:
    CF280C Game on Tree 概率与期望
    bzoj 3420: Poi2013 Triumphal arch 树形dp+二分
    bzoj 2111: [ZJOI2010]Perm 排列计数 Lucas
    bzoj 3709: [PA2014]Bohater 贪心
    bzoj 1396/2865: 识别子串 后缀自动机+线段树
    【教程】如何搭建一个自己的网站
    C#单例设计模式
    C#双缓冲代码
    Hibernate的查询功能
    hibernate事务规范写法
  • 原文地址:https://www.cnblogs.com/sntetwt/p/3510336.html
Copyright © 2011-2022 走看看