6

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

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

thanks.

5
  • ive tried nothing... and im all out of ideas man.. :P Commented Apr 12, 2012 at 18:56
  • stackoverflow.com/questions/6720402/… Commented Apr 12, 2012 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. Commented Apr 12, 2012 at 19:27
  • possible duplicate of How to pass two anonymous functions as arguments in CoffeScript? Commented Apr 12, 2012 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. Commented Apr 12, 2012 at 21:20

3 Answers 3

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
});
Sign up to request clarification or add additional context in comments.

2 Comments

I'm sorry my quick sample doesn't meet your requirements for perfect.
You're forgiven. FB.getLoginStatus receiveLogin, { scope }
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.

Comments

0

Another option:

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.