【发布时间】:2013-04-01 02:25:31
【问题描述】:
我正在尝试使用通过 coffeescript 编写的 github API 做一些事情。我对它很陌生,我在这个块上遇到了麻烦。
getRepos: (user)->
this.github.repos.getFromUser(
user: user,
type: "all",
sort: "updated",
direction: "desc"
(err,res)-> console.log(JSON.stringify(res))
)
目前正在编译为
getRepos: function(user) {
return this.github.repos.getFromUser({
user: user
}, {
type: "all",
sort: "updated",
direction: "desc"
}, function(err, res) {
return console.log(JSON.stringify(res));
});
而我不想在 user:user 后面加上额外的括号,那就是它应该是这样的:
getRepos: function(user) {
return this.github.repos.getFromUser({
user: user,
type: "all",
sort: "updated",
direction: "desc"
}, function(err, res) {
return console.log(JSON.stringify(res));
});
coffeescript 缺少什么?
编辑:这是完整的代码
GitHubApi = require("node-github");
gitLoader =
github: new GitHubApi({
version: "3.0.0",
timeout: 5000
});
authenticate: ->
this.github.authenticate({
type: "basic",
username: username,
password: password
})
getRepos: (user)->
this.github.repos.getFromUser(
user: user,
type: "all",
sort: "updated",
direction: "desc"
(err,res)-> console.log(JSON.stringify(res))
)
getFollowers: ->
this.github.user.getFollowingFromUser(
user: "example",
(err, res)->console.log(JSON.stringify(res));
)
编辑 2:认为它一定是某种间距问题。当我复制粘贴从编辑器复制的副本时,它编译正确。 = /
【问题讨论】:
-
无法用您的代码复制它。 link
-
我也是 - 检查您的间距,并注意您不需要逗号来分隔这些对象属性。您可以在这里进行实验:js2coffee.org/#coffee2js
-
是的,如果我在
user: ...前面添加一个额外的空格,我会得到不正确的输出 -
嗯。设法让它工作。一定是某种间距问题...
标签: json coffeescript