问题
I can better explain my case by code snippet
var cascadiaFault = new google.maps.Polyline({
paths: [
new google.maps.LatLng(49.95, -128.1),
new google.maps.LatLng(46.26, -126.3),
new google.maps.LatLng(40.3, -125.4)
]
});
the value of paths property should be assigned from external variable pathsTemp
var pathsTemp = [];
for (var i = 0; i < boxes.length; i++) {
var bounds = boxes[i];
// Perform search over this bounds
pathsTemp.push(bounds.getCenter());
}
var cascadiaFault = new google.maps.Polyline({
paths: pathsTemp;
});
Its not working..
Other options that I tried
paths = pathsTemp; -- Not workingpaths: paths.push(pathsTmep) -- No syntactic error but, uncaught reference error at runtime when this line is reached
PS: I don't have javascript background and unfortunately I don't have time to start reading the syntax and rules from scratch (However, I can understand most of the js code already written)
回答1:
Well, I got what the problem is
- The correct syntax is
paths: pathsTemp
var pathsTemp = [];
for (var i = 0; i < boxes.length; i++) {
var bounds = boxes[i];
// Perform search over this bounds
pathsTemp.push(bounds.getCenter());
}
var cascadiaFault = new google.maps.Polyline({
paths: pathsTemp
});
- The above code is syntactically correct, but the problem is it should be
pathinstead ofpaths
Though the sample example presented at https://developers.google.com/maps/documentation/javascript/geometry#isLocationOnEdge
uses paths, it works with path for me. May be a typo in API documentation
As expected, documentation bug logged
with reference to this stackoverflow discussion
回答2:
for the person who down voted the question : please take a look at this misleading example snippet from google documentation and change your opinion if it makes sense to you (Reputation matters a lot here, for a beginner like me)
来源:https://stackoverflow.com/questions/31156657/javascript-syntax-to-set-object-property-value-from-external-variable