js 中caller的意思,这段代码看不懂,帮看看

//主接口
win.laydate = function(options){
    options = options || {};
    try{
        as.event = win.event ? win.event : laydate.caller.arguments[0];
    } catch(e){};
    Dates.run(options);
    return laydate;
};

这个laydate.caller.arguments[0]啥意思?

阅读 2.2k
2 个回答

调用 laydate 函数的函数的第一个参数。

function fun(a,b){
    laydate(a+b);
}

function laydate(c){
    // 调用 laydate 函数 的函数(fun) 的第一个参数(a)。
    console.log(laydate.caller.arguments[0]);
    console.table([laydate.caller.arguments,arguments]);
}

fun(1,2);

直接写 函数名(laydate)不优雅,后期函数改名后都要改,可以用callee,最终实现的效果都是一样的。

function fun(a,b){
    laydate(a+b);
}

function laydate(c){
    console.log(arguments.callee.caller.arguments[0]);
}

fun(1,2);

If the function f was invoked by the top level code, the value of f.caller is null, otherwise it's the function that called f.
这东西好像不建议使用。

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题