I have a strange error. When I put layerinformation into a localvariable it works but when i try to put it in a variable which I want to use through my whole component it gives this error:

```
ERROR TypeError: Cannot read property 'setLayer' of undefined

```

This is my code:

```
 this.map.getLayers().forEach(function(layer, i) {
          if (layer instanceof Group) {

              var layerinfo = layer.getLayers();

          }
        });

```

The code above works fine but when I change var layerinfo into this.setLayer I get the TypeError can someone explain me why?

Thx!