let getLowerUpperBoundFromValue=(bound , idToValue)=>{
// Returns the value of the variable previously generated if "value" is a variable name or return "value" if its a number .
// bound : can be a direct integer or a variable name.
// idToValue : contains the id to value mapping which must contain a variable whose name must be equal to 'bound' parameter if its a variable name .
if(isNaN(Number(bound)))
{
Object.entries(idToVarStatesGlobal).forEach(idStatePair=>{
let id= idStatePair[0] , varState = idStatePair[1] ;
if(varState.name===bound){
console.log("check now Returning idTovalue[id]" , idToValue , id , idToValue[id] , Number(idToValue[id]));
return Number(idToValue[id]) ;
}
})
}
else return Number(bound);
}
このようなコンソールログを実行すると、次のようになります。
console.log('check now: ' , getLowerUpperBoundFromValue(varState.lowerbound , idToValue)) ;
私はこのようなログ出力を取得します:
check now Returning idTovalue[id] {PSfCL5hBm: 69} PSfCL5hBm 69 69
inputGeneration.js:99 check now: undefined
Number(idTovalue[id])
evaluesが通常の値69になっているのに、関数が未定義を返すのはなぜですか?
forEachコールバックは別のメソッドであるため、何も返されません。の呼び出しを削除し、スコープを維持.forEach
するfor of
ループに置き換えましたreturn
let getLowerUpperBoundFromValue=(bound , idToValue)=>{
// Returns the value of the variable previously generated if "value" is a variable name or return "value" if its a number .
// bound : can be a direct integer or a variable name.
// idToValue : contains the id to value mapping which must contain a variable whose name must be equal to 'bound' parameter if its a variable name .
if(isNaN(Number(bound)))
{
for (let idStatePair of Object.entries(idToVarStatesGlobal)) {
let id= idStatePair[0] , varState = idStatePair[1] ;
if(varState.name===bound){
console.log("check now Returning idTovalue[id]" , idToValue , id , idToValue[id] , Number(idToValue[id]));
return Number(idToValue[id]) ;
}
}
}
else return Number(bound);
}
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加