0

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');
Lhfcws
  • 302
  • 1
  • 3
  • 15

2 Answers2

3

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'
Ven
  • 19,015
  • 2
  • 41
  • 61
  • Well, thx, now I'm using the second solution. and one more question , what's the difference between callback and backcall? :) – Lhfcws Mar 30 '13 at 06:22
  • Callback is forward `->` and backcall is backward `<-` – Ven Mar 30 '13 at 10:56
1

that worked for me @ Livescript 1.2.0

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

Enjoy)

Daniel K
  • 91
  • 1
  • 6