Hello, Framers! I have a question about coffeescript.Could you explain difference between these two codes?
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:
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 parameters2. layer.animate instead of layerA.animate
and pass a layer as parameter.
LayerA.on Events.Click, -> EventA(@)(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, -> EventA(@)
The case 1 will limit your flexibility and may be just more confusing.
You may find the coffescript.org "try coffeescript" page helpful
I asked this because of for-loop case. Please check this 2 cases.http://share.framerjs.com/me5yqdoikq33/