简体   繁体   English

将变量传递给内部函数

[英]Passing variable to an inner function

function getSsrBandAid(ssn,id) {    
   DWREngine._execute(_ajaxConfig._cfscriptLocation, null, 'getSsrBandAid', ssn, doQueryResults); //calling method in decRequest.cfc    
   function doQueryResults(t){  
     xmlT = loadXMLString(t);  
     alert(ssn);            
   }
}

Trying to pass ssn to doQueryResults() function. 尝试将ssn传递给doQueryResults()函数。
I have tried to this doQueryResults(t,ssn) but it doesn't work. 我已经尝试过这个doQueryResults(t,ssn),但是它不起作用。

Any help appreciated. 任何帮助表示赞赏。

Thanks 谢谢

ECMA-/Javascript has a static (lexical) scope. ECMA // Javascript具有静态(词汇)范围。 It also has the feature, that an "innerContext" closes over an "outerContext". 它还具有“ innerContext”关闭“ outerContext”的功能。

To make a long long story short, your doQueryResults() will copy the parent Scope (which is getSsrBandAid). 长话短说,您的doQueryResults()将复制父作用域 (即getSsrBandAid)。 That includes the Activation object which holds the arguments. 这包括保存参数的Activation对象

So if alert(ssn); 因此,如果alert(ssn); is undefined, it is also undefined when calling getSsrBandAid() . 是undefined,在调用getSsrBandAid()时也未定义。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM