javascript - 意外的标记运算符 «=»,预期的 punc «,»

标签 javascript jslint

我收到以下错误

Parse error: Unexpected token operator «=», expected punc «,» Line 159, column 26

这是我的代码

  function fitBounds(type="all", shape=null) {
    var bounds = new google.maps.LatLngBounds();

    if ( type == "all" ){
      if ((circles.length > 0) | (polygons.length > 0)){
        $.each(circles, function(index, circle){
          bounds.union(circle.getBounds());
        });
        $.each(polygons, function(index, polygon){
          polygon.getPath().getArray().forEach(function(latLng){
            bounds.extend(latLng);
          });
        });
      }
    }
    else if ( (type == "single") && (shape != null) ) {
      if (shape.type == google.maps.drawing.OverlayType.MARKER) {
        marker_index = markers.indexOf(shape);
        bounds.union(circles[marker_index].getBounds());
      }
      else {
        shape.getPath().getArray().forEach(function(latLng){
          bounds.extend(latLng);
        });
      }
    }

    if (bounds.isEmpty() != true)
    {
      map.fitBounds(bounds);
    }
  }

最佳答案

您正在尝试使用 Default parameters ,这是 JavaScript 的前沿功能 limited support .

除非您打开 ES6 选项,否则 JS Lint 会拒绝它们。

关于javascript - 意外的标记运算符 «=»,预期的 punc «,»,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40780273/

相关文章:

javascript - 不要为特定的 css 类添加类

javascript - 如何处理循环中的时刻日期?

javascript - JSLint 会改进您的 Javascript 编码吗?

javascript - JSLint 正则表达式违规问题

javascript - 在元素附近激活悬停的方法

javascript - 尝试通过 AJAX 针对我的 WebAPI 发出 GET 请求,仅在 Firefox 和 Chrome 中返回 401 Unauthorized

javascript - 在 Web 上的 Firebase 中将电话号码与 Facebook 和 Gmail 帐户相关联

javascript - 我如何处理 JSLint 错误和警告?

javascript - jsLint for 循环声明

JavaScript:JSLint 错误 "The body of a for in should be wrapped in an if statement to filter unwanted properties from the prototype"