Question

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');
Was it helpful?

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'

OTHER TIPS

that worked for me @ Livescript 1.2.0

(
<- $ 'h1' .on 'click'
alert 'boom!'
)
(
<- $ 'h2' .on 'click'
alert 'kaboom!'
)

Enjoy)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top