代码之家  ›  专栏  ›  技术社区  ›  atoms

由于在Internet Explorer 11中使用默认参数值而引发的JS错误

  •  -1
  • atoms  · 技术社区  · 8 年前

    我有一些js/javascript在edge、chrome、firefox和safari中运行良好。在ie11中测试时,它返回 : Expected ')'

    我相信是因为 function(oTR = null) 然而,这怎么可能呢?ie11肯定支持这种语法/逻辑吗?!

    这里有一个链接 MS error page 控制台产生的

    oSC = {
      oItems : {
        oTR: null,
      },
      GetProductKey : function(oTR = null){
        return $((oTR ? oTR:oSC.oItems.oTR)).attr("data-code");
      },
    }
    
    1 回复  |  直到 8 年前
        1
  •  2
  •   christian wuensche    8 年前

    可以向三元运算符添加一个简单条件

    oSC = {
      oItems : {
        oTR: null,
      },
      GetProductKey : function(oTR){
        return $((typeof oTR === 'YOUR_EXPECTED_TYPE' ? oTR :oSC.oItems.oTR)).attr("data-code");
     },
    }