zoukankan      html  css  js  c++  java
  • javascript 动态添加参数后再执行的方法

    function myFunction(test1, test2) {
        //用apply传入的参数必须显式声明,按放入顺序取   
        //alert(extendStr);   
        alert(test1);
        alert(test2);
        //绑定property后不用传入也可以通过函数本身调用,但不能用this   
        alert("myFunction.extendStr = " + myFunction.extendStr);
    }


    function extendFunction(callbackFunction, extend) {
        var extendStr = "this is extend string!";
        var args = [];
        if (typeof (extend) == "object") {
            for (var property in extend) {
                //绑定property,可以通过函数本身调用   
                callbackFunction[property] = extend[property];
                //把参数值按照顺序放入到数组中,通过apply传入   
                args.push(extend[property]);
            }
        }
        //绑定property,可以通过函数本身调用   
        callbackFunction["extendStr"] = extendStr;
        //把参数值按照顺序放入到数组中,通过apply传入   
        args.push(extendStr);
        //动态调用函数,把参数值数组传入   
        alert('c');
        callbackFunction.apply(this, args);
    }
    //动态扩展函数并执行,一般用在ajax回调函数的处理中
    extendFunction(myFunction, { test1: 'aaa', test2: 'bbb' });

  • 相关阅读:
    解决SecureCRT中文显示乱码
    能大大提升工作效率和时间效率的9个重要习惯
    PHP基础知识
    CI学习相关地址
    IE8引入JavaScript
    IE9以下不支持placeholder属性
    IE8浏览器兼容性问题
    简单的DOS命令
    Linux常用运维指令
    log4j日志+面向切面监控异常
  • 原文地址:https://www.cnblogs.com/amylis_chen/p/1741809.html
Copyright © 2011-2022 走看看