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

What is Framer? Join the Community
Return to index
Jeongmin Kim
Posted Nov 05 - Read on Facebook

Hello, Framers!
I have a question about coffeescript.
Could you explain difference between these two codes?


Marcelo Eduardo Oliveira


So case 1:

So you created a function, called EventA, that needs 2 parameters ( event and layer ) to execute.

The odd thing, is that ... you are not using those parameters ( or at least one ) you're simply calling the layer Directly, and the Event handler you created:

layerA.on(Events.Click, EventA)

is simply calling EventA ( without any parameters ) when the layer is clicked.

So, the (event, layer) part of your EventA definition is useless.

In order to that part to make sense you would have to do it :

1. remote the event from the parameters
2. layer.animate instead of layerA.animate

and pass a layer as parameter.

LayerA.on Events.Click, ->
(the new line and indentation is important here, if you omit, the function EventA will simply be called automatically.

The confusing thing here maybe the way coffeescript deals with functions / Events and the Arrow ( function ) definition / call :

the case Event Handler could be re-written like this:

layerA.on Events.Click , EventA
# what you're doing is : anytime Click happens, call EventA

in case 2, you're doing a anonymous function ( the arrow ) that has only one command : EventA()

Sounds little confusing, sorry for the long answer, but to keep things simple, use case 2, but with proper indentation :

layerA.on Events.Click, ->

The case 1 will limit your flexibility and may be just more confusing.

Andrew Nalband

You may find the "try coffeescript" page helpful

Jeongmin Kim

I asked this because of for-loop case. Please check this 2 cases.

Read the entire post on Facebook