geoadmin / ol3

OpenLayers 3
http://ol3js.org/
Other
11 stars 6 forks source link

Don't use for ... in loop #73

Closed streist closed 10 years ago

streist commented 10 years ago
ga.Tooltip.prototype.createFeatures_ = function(response) {
  if(response["results"].length > 0) {
    var features = new Array;
    for(var i in response["results"]) {
      var feature;
      if(response["results"][i].geometry.type === "Point") {
.
.
.

The for ...in loop triggers this error, when trying to get the tooltip : Uncaught TypeError: Cannot read property 'type' of undefined

cedricmoullet commented 10 years ago

Do you have an example where it occurs ?

streist commented 10 years ago

http://cmsr.testlt.intranet.vbs.admin.ch/internet/cadastre/de/home/topics/state.html?CFC_cK=1396526916823&CFC_scrollTop=0

gjn commented 10 years ago

Wrong usage of for..in loop. i already contains the array element. Try

if (i.geometry.type === "Point")

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for...in?redirectlocale=en-US&redirectslug=JavaScript%2FReference%2FStatements%2Ffor...in

oterral commented 10 years ago

No it contains the property name (in a array it's 1,2,3,4,5 ...) not the value of the property

gjn commented 10 years ago

oops. of course. stroke by big berta, I guess.