6

I am not sure how to write this in CS. maybe some1 can help:

FB.getLoginStatus(function (response) {} , {scope : scope})

thanks.

d4rklit3
  • 417
  • 1
  • 5
  • 12
  • ive tried nothing... and im all out of ideas man.. :P – d4rklit3 Apr 12 '12 at 18:56
  • http://stackoverflow.com/questions/6720402/in-coffeescript-how-can-you-make-a-function-call-with-anonymous-functions-as-pa – Matt Ball Apr 12 '12 at 19:18
  • @d4rklit3 if I were you I would back off coffeescript for a while and try to get a good grasp of javascript first. – Ricardo Tomasi Apr 12 '12 at 19:27
  • possible duplicate of [How to pass two anonymous functions as arguments in CoffeScript?](http://stackoverflow.com/questions/6463052/how-to-pass-two-anonymous-functions-as-arguments-in-coffescript) – mu is too short Apr 12 '12 at 19:27
  • @RicardoTomasi i read your comment. and i disagree with you. perhaps you should be more tactful. just some friendly real world advice for you buddy. – d4rklit3 Apr 12 '12 at 21:20

3 Answers3

10

You would write some CoffeeScript like so...

FB.getLoginStatus(
  (response) -> 
    doSomething()
  {scope: scope})

Which would convert to the JavaScript like so...

FB.getLoginStatus(function(response) {
  return doSomething();
}, {
  scope: scope
});
scottheckel
  • 9,106
  • 1
  • 35
  • 47
4
FB.getLoginStatus(function(response) {}, {
  scope: scope
});

in JavaScript is:

FB.getLoginStatus(
  (response) ->
  { scope }
)

in CoffeeScript.

To answer your question about multiple parameters further have a look at these examples:

$('.main li').hover(
  -> $(@).find('span').show()   
  -> $(@).find('span').hide()
)

In CoffeeScript equals to:

$('.main li').hover(function() {
  return $(this).find('span').show();
}, function() {
  return $(this).find('span').hide();
});

in JavaScript.

An even simpler example regarding handling multiple parameters (without anonymous functions) would be:

hello = (firstName, lastName) ->
  console.log "Hello #{firstName} #{lastName}"

hello "Coffee", "Script"

in CoffeeScript compiles to:

var hello;

hello = function(firstName, lastName) {
  return console.log("Hello " + firstName + " " + lastName);
};

hello("Coffee", "Script");

in JavaScript.

datentyp
  • 1,371
  • 12
  • 9
0

Another option:

FB.getLoginStatus(((response) ->),{scope})
SethWhite
  • 1,891
  • 18
  • 24