gpt4 book ai didi

javascript - 有没有办法从当前函数中获取当前函数?

转载 作者:IT王子 更新时间:2023-10-29 03:06:04 24 4
gpt4 key购买 nike

抱歉,标题真的很奇怪,但这是我想做的:

var f1 = function (param1, param2) {

// Is there a way to get an object that is ‘f1’
// (the current function)?

};

如您所见,我想从匿名函数中访问当前函数。

这可能吗?

最佳答案

给它命名。

var f1 = function fOne() {
console.log(fOne); //fOne is reference to this function
}
console.log(fOne); //undefined - this is good, fOne does not pollute global context

关于javascript - 有没有办法从当前函数中获取当前函数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4654388/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com