您的位置:首页 > Web前端 > JavaScript

JavaScript的caller属性(函数)

2014-09-15 22:20 218 查看
获取调用当前函数的函数。
functionName.caller

备注functionName 对象是任何正在执行的函数的名称。caller 属性只有当函数正在执行时才被定义。 如果函数是从 JavaScript 程序的顶层调用的,则 caller 包含 null。如果在字符串上下文中使用 caller 属性,则其结果和 functionName.toString 相同,也就是说,将显示函数的反编译文本。下面的示例阐释了 caller 属性的用法:JavaScript
function FuncA() {
if(FuncA.caller==null){
alert("called from top level");
}else{
alert("called from another function");
}
}
function FuncB(){
FuncA();
}
FuncA();//called from top level
FuncB();//called from another function

                                            
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
相关文章推荐