我是一个CoffeeScript初学者。为什么CoffeeScript在下列情况下需要括号?
这是从输出:http://js2coffee.org/
的.js:
var prevPost = Posts.findOne({position: this.position - 1});
.coffee:
prevPost = Posts.findOne(position: @position - 1)
的.js:
Posts = new Meteor.Collection('posts');
.coffee:
@Posts = new Meteor.Collection("posts")
为什么不圆括号在这里?
的.js:
Posts.update(nextPost._id, {$set: {position: nextPost.position - 1}});
.coffee:
Posts.update nextPost._id,
$set:
position: nextPost.position - 1
我的猜测(也是coffeejs的新手)是它与参数的数量和/或类型有关。注意在前两种情况下你只有一个参数,而在第二种情况下你有两个,其中一个是对象?对于方法的返回,你正在做什么似乎也很重要。 'var foo = foo.bar(...'vs'foo.bar(...' –
是关于j2coffee还是关于CoffeeScript的问题? –
@Michael_Scharf CoffeeScript – alexchenco