2016-11-02 10 views
0

私は物事を参照する関数を持っています。バグを修正するために、私は他のケースステートメントを削除しました(彼らは変更も問題も修正しません)。私はreturnも削除しました。これは、この段階では無関係です。値が表示されているにもかかわらず、Null/Undefinedとしてのパラメータチェック

何かの理由で、Chrome Consoleにtype = 'id'if (type === null || "" || "undefined")が毎回起動すると伝えているにもかかわらず、私はDOM内の要素を渡します。Referencer('id', 'hello')この

if (type === null || "" || "undefined") { 

https://output.jsbin.com/secuciyeko

function Referencer(type, value) { 

    // Standard Declaration 
    "use strict"; 

    // Open Console Group 
    window.console.groupCollapsed("[Scriptbase.js]/[Referencer] @ " + Scriptbase.Time()); 

    // Log Status 
    window.console.info("[Process Started @ " + Scriptbase.Time() + "]"); 







    /* ------- Computation ------- */ 

    // Local Variables 
    var a = null; 

    // Log Status 
    window.console.log("[Success @ " + Scriptbase.Time() + "]: Checking for unusable values."); 

    // Value Validation 
    if (type === null || "" || "undefined") { 

     // Log Status 
     window.console.error("[Failure : " + Scriptbase.Time() + "] : Failure to look up '" + type + "' with the value '" + value + "'."); 

     // Close Console Group 
     window.console.groupEnd(); 

     // Exit Method 
     return; 

    } 
    if (value === null || "" || "undefined") { 

     // Log Status 
     window.console.error("[Failure : " + Scriptbase.Time() + "] : Failure to look up '" + type + "' with the value '" + value + "'."); 

     // Close Console Group 
     window.console.groupEnd(); 

     // Exit Method 
     return; 

    } 

    // Log Status 
    window.console.log("[Success : " + Scriptbase.Time() + "] : Looking up '" + type.toUpperCase() + "' with the value of '" + value + "'."); 

    // Look Up Value 
    switch (type) { 
     case "id": 

      // Variable Assignment 
      a = document.getElementById(value); 

      // Log Status 
      window.console.log("[Success : " + Scriptbase.Time() + "]: Found an DOM ID of '" + value + "'."); 

      // Break Case 
      break; 
    } 
} 

答えて

1

あなたが言っている:null

  • または空の文字列であれば等しい

    • type場合はここで

      はJSBinです真である
    • または文字列'undefined'

    trueの場合は、実際に''または'undefined'typeを比較されていません。

    あなたはそれが空の場合、nullまたはundefinedは、それが条件になります次に

    if (!type) { 
    

    に変更することができます。

    について

    を読みます
  • 関連する問題