I want to convert a jQuery function written in JavaScript into Coffeescript, which gets two functions as parameters. I'm new to Coffeescript and I'm a little stuck here. The original function is something like:
$('#target').toggle(function() {
alert('First handler for .toggle() called.');
}, function() {
alert('Second handler for .toggle() called.');
});
How does it look like in Coffeescript?
An easy way to see how something works in coffeescript in real time is to go over to the official website and use the "Try Coffeescript" dropdown pane. One way I found of getting it to output the exact same code as what you wanted was to do this:
$('#target').toggle ->
alert 'First handler for .toggle() called.'
, ->
alert 'Second handler for .toggle() called.'
Give it a try. It may feel a bit odd typing code into a website, but I've certainly found it useful.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With