0

I am making a resume in HTML5 with the help of svg.js. I have made 5 labels like this:

var las = lang.text(function(add){
  add.tspan('Läsa').dx(178).dy(145)
})

same thing for tal, skr, lys and ord

To make as DRY code as possible I then style them like this:

var labels = [las, tal, skr, lys, ord]
labels.forEach(function(lab){
  lab.font({
    family: 'Helvetica',
    size: 18
  })
})

Now, my question is mostly about style, but what are the ways to go about this?

What I would like to do is just call forEach directly on the array without having to clutter with variables, like this:

[las, tal, skr, lys, ord].forEach(function(lab){
  lab.font({
    family: 'Helvetica',
    size: 18
  })
})

But that doesn't work, although I don't really understand why. The MDN article for the error message doesn't make me any wiser. Sorry if this question seems silly, but either my google-fu isn't good enough or this really is so silly that no one bothered to ask it before :P

klesus
  • 196
  • 6
  • Please add a fiddle so we can debug whats going wrong – Fuzzyma Feb 23 '17 at 21:20
  • 1
    Add a ";" before the array literal. When you remove the newlines your code reads `somefunction()[your Array liteal]` - the parser trys acces an index which isnt there. Therefore the error message you (most likely) get. But without fiddle or further code its just tryharding – Fuzzyma May 03 '17 at 11:04

0 Answers0