Javascript JS嵌套函数

Javascript JS嵌套函数,javascript,Javascript,我正在使用嵌套函数 Function mainfunction (callbackfun) { //some code + function (score) { var score = scoreString; alert(scoreString); callbackFun(score); } } //--> I return this value to my calling function mainfuncti

我正在使用嵌套函数

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
out中像这样访问该值

var fetchvalue ;

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

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

整理一下代码,纠正拼写错误等,并观看
main函数的输出
为您提供此工作脚本。很难说这是否回答了您的问题,但它确实会向回调函数发送一个变量,然后从该回调函数获取一个返回值

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 
}); 

你试过了吗?提示:JS区分大小写,因此它应该是
function
而不是
function
,并且您的参数名为
callbackfun
,而不是
callbackfun
。修复此问题后,代码将执行以下操作:。这就是你想要的吗?问题是什么?你想用你的代码实现什么?编辑:确定,编辑后问题可见;-)