2016-11-24 2 views
2

я получаю следующее сообщение об ошибкеНеожиданный токен оператор «=», как ожидается Punc «»

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); 
    } 
    } 
+4

Где находится 159 строк? PS: Это действительно плохо спрошенный вопрос у кого-то из вашего представителя ... – AxelH

ответ

9

Вы пытаетесь использовать Default parameters, которые являются кровотечение кросс-функции JavaScript с limited support.

JS Lint отвергает их, если вы не включили опцию ES6.

1

@Quentin в точности соответствует: вам нужен параметр es6.

Там много больше, что не может JSLint, однако, в частности, использование вами ==, который является «принуждающим оператором» - проверить JSLint on equality - и bitwise option in the jslint section (нет прямой ссылки на JSLint директивы, я не думаю, поэтому я связался чуть выше него). Как предлагает @AxelH, скорее всего вы действительно хотите нас спросить. ; ^)

Вот версия, которая нарисована на JSLint.com, как сегодня. Обратите внимание на /*jslint директиву линии в верхней части, которая включает в es6 tag:

/*jslint es6, white, browser */ 
/*global google, $ */ 

// These weren't declared, so I'm assuming they're 
// within scope in your snippet's context. 
// I put others that felt like globals (google, $) 
// into globals, above. 
var marker_index; 
var markers; 
var circles; 
var polygons; 
var map; 

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

    if (type === "all"){ 
    // not sure why you're using bitwise `|` here. 
    // I think this'll be equivalent, though you should 
    // be able to set `bitwise` as an option if it's not. 
    // Still, you're evaluating to booleans, so `|` doesn't 
    // seem appropriate here. 
    if ((circles.length > 0) || (polygons.length > 0)){ 
     $.each(circles, function(ignore, circle){ 
     bounds.union(circle.getBounds()); 
     }); 
     $.each(polygons, function(ignore, 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()) 
    { 
    map.fitBounds(bounds); 
    } 
} 
0

@Quentin правильно с его ответом. Вы получаете синтаксическую ошибку из-за причин, о которых он упомянул. Что я могу добавить к этому, так это то, что вы можете попробовать отказаться от синтаксиса EC6 и переписать свою функцию на старый хороший JS.

// change from 
function fitBounds(type="all", shape=null) 

// change to 
function fitBounds(type="all", shape) 
Смежные вопросы