2017-02-27 79 views
1

我有一个辅助函数,它不在If或Else上进行评估。If/Else Statement Not Evaluating

我知道函数被调用,因为我有nlapiLogExecution,这是你在NetSuite中调试的方式。有关正在记录什么的说明与代码有关。

这怎么可能?我也尝试使用==运营商。我也尝试将它设置为函数内部的一个变量(我认为这是不必要的)。

function convertUnit(unit, cubicMeters){ 
    nlapiLogExecution('DEBUG','convertUnitFunction',typeof(unit)) 
    // typeof is String 
    nlapiLogExecution('DEBUG','convertUnitFunction',unit) 
    // value is Each 
    if (unit === 'Each'){ 
     return cubicMeters 
     nlapiLogExecution('DEBUG','equals Each', cubicMeters) 
     // does not log here 
    } 
    else { 
     nlapiLogExecution('DEBUG','else statements', 'equals else') 
     // Does not log here 
    } 
} 
+1

如果“if”条件为真,你的函数返回*之前*达到日志功能。 – nnnnnn

+0

将'返回cubicMeters'作为块内的最后一条语句 – jeff

+0

@nnnnnn是你的权利。我想我在下游的某个地方还有其他问题。 – nzaleski

回答

3

您正在进入if语句,但在你面前功能return S可登录任何东西。请尝试关闭return和日志语句的顺序:

function convertUnit(unit, cubicMeters){ 
    nlapiLogExecution('DEBUG','convertUnitFunction',typeof(unit)) 
    // typeof is String 
    nlapiLogExecution('DEBUG','convertUnitFunction',unit) 
    // value is Each 
    if (unit === 'Each'){ 
     nlapiLogExecution('DEBUG','equals Each', cubicMeters) 
     // will log something now if you pass 'Each' 
     return cubicMeters 
    } 
    else { 
     nlapiLogExecution('DEBUG','else statements', 'equals else') 
     // will log something if the else branch is taken 
    } 
} 
0

你正在返回它到达nlapiLogExecution'Each'部分之前。不知道为什么它不在其他运行,除非你只是通过'Each'