对象中的尾随逗号

Trailing comma in object

$.ajax({
   url:"test.html",
   cache: false,
   success: function(html){
      $("#results").append(html);
   },
});      

最后一个键值对 (success:function) 末尾有一个逗号。我想知道 Internet Explorer 是否以逗号结尾。 代码在 google chrome 和 Mozilla Firefox 中运行良好。 但在某些情况下,我会收到 JavaScript 错误 "Expected Identifier, String or Number"。 我想知道尾随逗号是导致此错误的原因。

这与Ajax完全无关。这完全是关于对象字面量的:

{
  url:"test.html",
  cache: false,
  success: function(html){
    $("#results").append(html);
  },
}

在 ES5 之前,对象字面量中的尾随逗号是被禁止的。

Internet Explorer 直到版本 9 才支持它们(并且可能仅当 Doctype 触发标准模式时)。

reference