Home > Backend Development > PHP Tutorial > javascript - 函数内如何知道调用它的函数的名称?

javascript - 函数内如何知道调用它的函数的名称?

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-06 20:37:08
Original
1087 people have browsed it

如:

<code>function a(){
    b();
}
function b(){
    console.log(a)
}
</code>
Copy after login
Copy after login

a()不向b()传值的情况下,函数b()如何知道调用它的是a()
js或者php都想知道有没有这种方法

回复内容:

如:

<code>function a(){
    b();
}
function b(){
    console.log(a)
}
</code>
Copy after login
Copy after login

a()不向b()传值的情况下,函数b()如何知道调用它的是a()
js或者php都想知道有没有这种方法

js:arguments.callee.caller

在javascript的函数内,arguments.callee是这个函数本身,而函数的caller则是这个函数的调用者(函数的调用者只有函数调用期间/函数内部才存在)。

PHP的话用debug_backtrace

Related labels:
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Issues
What are JavaScript hook functions?
From 1970-01-01 08:00:00
0
0
0
What is JavaScript garbage collection?
From 1970-01-01 08:00:00
0
0
0
c++ calls javascript
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template