簡體   English   中英

如何獲得內部函數的返回值

[英]how to get internal function return value

我需要從另一個函數中調用一個Javascript,如下所示。 我需要從內部函數獲取返回值。 請看下面。

如何從函數getpopupbox()獲得返回值?

function first(){
     var type = getpopupbox();
     if( type == 'yes' ) 
       //Some code here
     if( type == 'no' ) 
       //Some code here 
     if( type == 'yes/no' ) 
       //Some code here 
}
function getpopupbox(){
 // I have 2 cases here
  if( case == '2' )
     return 'yes';
  if( case == '1' )
     return 'no';
  if( case == '0' )
     return 'yes/no'; 
}

您不能將case用作變量名。 這是JavaScript中的保留關鍵字。

當您嘗試解析該函數​​時,腳本可能會崩潰,並且我想如果您檢查控制台,就會在此看到錯誤。

您的case變量弄亂了switch case東西

將變量重命名為另一個名稱。

像這樣

var condCase='2';
function first(){
     var type = getpopupbox();
     if( type == 'yes' ) 
       //Some code here
     if( type == 'no' ) 
       //Some code here 
     if( type == 'yes/no' ) 
       //Some code here 
}
function getpopupbox(){
 // I have 2 cases here
  if( condCase== '2' )
     return 'yes';
  if( condCase== '1' )
     return 'no';
  if( condCase== '0' )
     return 'yes/no'; 
}

用其他名稱重命名case變量。case是js中的保留關鍵字。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM