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

What is Framer? Join the Community
Return to index
Chris Camargo
Posted Jul 29 - Read on Facebook

I have several buttons inside of a ScrollComponent that are nested within panels. On click, I'm printing both this.screenFrame.y and this.y, and I'm getting wildly different numbers, when they should only be around 200 pixels apart.

Can someone shed some light on where this difference is coming from?


Koen Bok

cc Jonas

Jonas Treub

This seems to be a reference thing. If I replace eachButton with this (@) you get the right values. Can you confirm Chris?

Chris Camargo

D'oh! Thank you, Jonas!

Chris Camargo

Douwe Homans

Hi Jonas Treub and Chris Camargo, I looked into this out of interest. see below coffeescript -> JS. var eachButton get's declared once outside of the for loop.

Therefore ever "function() {
return print(eachButton.y);
});" creates a closure closing in that same eachButton.

So indeed they all have a reference to the same 'eachButton'. I don't understand why coffeescript decides to 'not create' a closure per iteration. If you see the javascript it's immediately clear you'll need to use this. In coffeescript it's not that clear in my opinion.

Read the entire post on Facebook