gpt4 book ai didi

javascript - JS 嵌套函数

转载 作者:行者123 更新时间:2023-11-30 18:09:24 25 4
gpt4 key购买 nike

我正在使用嵌套函数

Function mainfunction (callbackfun) {
//some code + function (score)
{
var score = scoreString;
alert(scoreString);
callbackFun(score);
}
} //--> I return this value to my calling function

mainfunction(function (anystring){
alert(anystring); //-> this would return me the value in callbackfun
});

我想要的是访问 anystring 中的那个值,就像

var fetchvalue ;

mainfunction(function (anystring){
fetchvalue =anystring; //-> this would return me the value in callbackfun
});

如果我在正确的轨道上,请指导我。

最佳答案

稍微整理一下您的代码,更正拼写错误等...,并观察 mainfunction 的输出,即可获得此工作脚本。很难说这是否回答了您的问题,但它确实将变量发送到回调函数,然后从该回调函数中获取返回值。

function mainfunction(callbackfun){
//some code + function (score)
var scoreString = Math.random()*10000000

var score = scoreString;
alert(callbackfun(score));

}; // --> i return this value to my calling function

mainfunction(function(anystring){
return anystring; //-> this would return me the value in callbackfun
});

关于javascript - JS 嵌套函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14999491/

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