This is a read-only archive of the Framer Community on Facebook.

What is Framer? Join the Community
Return to index
Isaac Weinhausen
Posted Dec 14 - Read on Facebook

TIP: For anyone who's ever used a for loop to set an event handler or some other kind of callback function, you may have noticed that your iterator variable is always set (stuck) to its last value when referenced in your handler/callback function. Usually, you're going to want the iterator's value for EACH step of your loop, not just the last. This is is where CoffeeScript's "do" keyword is useful. Here's a couple links that'll help you understand:

http://stackoverflow.com/questions/8220340/callbacks-only-see-last-value-from-loop

http://rzrsharp.net/2011/06/27/what-does-coffeescripts-do-do.html

2 Comments

Jordan Robert Dobson

Another trick I use is to use the custom property and store the value there so it's always around and aware of itself and where it's order is in the list.

items = []

for index in [0...10]
item = items[index] = new Layer
custom: index: index

item.onClick -> print @.custom.index

Eelco Lempsink

Great tip/reminder! We also cover this in the Scope section at the end of the programming guide: https://framerjs.com/getstarted/programming/#scope

Read the entire post on Facebook