javascript - js 中caller的意思,这段代码看不懂,帮看看
天蓬老师
天蓬老师 2017-04-11 13:28:22
[JavaScript讨论组]
//主接口
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)
ringa_lee

调用 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.
这东西好像不建议使用。

热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号