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

What is Framer? Join the Community
Return to index
Arturo Goicochea
Posted Nov 16 - Read on Facebook

Quick JS question:
Why is does the 'i' in a for loop different change it's value when used inside a click event?

When I do:
##################
for i in [0...1]
foo = i
layer.onClick ->
print i
print foo
##################

outside the click event, both i and foo = 0
inside the event, foo = 0, i = 1

(Look at image fore reference, or open example Framer file)

https://framer.cloud/seoCk

6 Comments

Alan Travis

Miklos Megyes is exactly right...

But do you understand the solution Arturo Goicochea?

If not I can put together something visual that will explain it.

Arturo Goicochea

Implemented :) Thanks guys!

Jordan Robert Dobson

This is why I just attach it to the layer via layer.custom = foo: i

You never know when you might need that value again and those do () -> can be a bit annoying.

Arturo Goicochea

I remembered you taught me that a while ago and is what I actually did for what I'm working on :D life saver ⚡️

Bhaskar Ravi

Scope! As someone who grew up on C++, Java, etc. Javascript still drives me nuts due to things like this :)

Read the entire post on Facebook