如何重构这个返回json对象的coffeescript方法?
getQuery: ->
p =
user:
__type: "Pointer"
className: '_User'
objectId: @model.id
private: false
q =
user:
__type: "Pointer"
className: '_User'
objectId: @model.id
spec =
projects:
collection: "Projects"
params:
where: JSON.stringify(p)
needsFetch: true
payments:
collection: "Payments"
params:
where: JSON.stringify(q)
needsFetch: true
var' p'和' q'几乎相同,但是' p'有{private:true}
提前谢谢。
答案 0 :(得分:0)
如果使用下划线,则可以扩展p
本质上是字典:
q = _.extend p, {private:false}