Fix a subtle bug in how style attributes where set

Before this patch, the closure created in the for loop was
referencing the loop variable, which changes.  After this
patch, it works the same way as setting normal attributes, which
is to call a separate function to create the closure from a
"snapshot" of the loop variable.