5

我不知道如何在 CS 中写这个。也许 some1 可以提供帮助:

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

谢谢。

4

3 回答 3

9

你会像这样写一些 CoffeeScript ......

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

哪个会像这样转换为JavaScript...

FB.getLoginStatus(function(response) {
  return doSomething();
}, {
  scope: scope
});
于 2012-04-12T18:56:38.390 回答
4
FB.getLoginStatus(function(response) {}, {
  scope: scope
});

在 JavaScript 中是:

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

在咖啡脚本中。

要回答有关多个参数的问题,请进一步查看以下示例:

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

在 CoffeeScript 中等于:

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

在 JavaScript 中。

关于处理多个参数(没有匿名函数)的一个更简单的例子是:

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

hello "Coffee", "Script"

在 CoffeeScript 中编译为:

var hello;

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

hello("Coffee", "Script");

在 JavaScript 中。

于 2012-04-12T19:48:11.923 回答
0

另外一个选项:

FB.getLoginStatus(((response) ->),{scope})
于 2016-07-21T22:18:43.900 回答