Skip to content Skip to sidebar Skip to footer

Javascript Syntax To Set Object Property Value From External Variable

I can better explain my case by code snippet the value of paths property should be assigned from external variable pathsTemp Its not working.. Other options that I tried paths =

Solution 1:

Well, I got what the problem is

  1. 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
});
  1. The above code is syntactically correct, but the problem is it should be path instead of paths

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

Solution 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)

enter image description here

Post a Comment for "Javascript Syntax To Set Object Property Value From External Variable"