Search code examples
javascriptnode.jscallbacklivescript

Livescript, How to end a unnested callback?


Reffering to: http://livescript.net Unnested callbacks and parentheses free chaining: LiveScript

<-! $ 'h1' .on 'click'
alert 'boom!'

JavaScript

$('h1').on('click', function(){
  alert('boom!');
});

How can I write livescript like this in Javascript?

JavaScript

$('h1').on('click', function(){
  alert('boom!');
});
alert('out of callback');

Solution

  • You can't. That's backcall.

    You have two options : use a do (I don't think it makes sense)

    do
      <- $ 'h1' .on 'click'
      alert 'boom!'
    

    ... Or just use a callback ?!

    $ 'h1' .on 'click' ->
      alert 'boom'