我在CoffeeScript中编写了一些代码,我无法弄清楚如何以正确编译的方式编写代码。
f = (id) ->
matching = app.list.where
id: id
if matching.length == 0
success = (data)->
if not data[id]
alert "couldn't find id " + id
else
b = new Thing data[id]
b.set 'id',id
b.trigger 'select'
error = ->
app.api.request 'info','GET',success,error,
ids: id
else
b = matching[0]
b.trigger 'select'
正在编译:
f = function(id) {
var matching;
return matching = app.list.where({
id: id
});
};
if (matching.length === 0) {
success = function(data) {
var b;
if (!data[id]) {
return alert("couldn't find id " + id);
} else {
b = new Thing(data[id]);
b.set('id', id);
return b.trigger('select');
}
};
error = function() {};
app.api.request('info', 'GET', success, error, {
ids: id
});
} else {
b = matching[0];
b.trigger('select');
}
如您所见,只有matching
的分配被解析为f
的一部分。
答案 0 :(得分:0)
f = (id) ->
matching = app.list.where id: id
if matching.length == 0
success = (data)->
if not data[id]
alert "couldn't find id " + id
else
b = new Thing data[id]
b.set 'id',id
b.trigger 'select'
error = ->
app.api.request 'info','GET',success,error,
ids: id
else
b = matching[0]
b.trigger 'select'