我已经生产了几个月的以下咖啡脚本:
yearSource = (yearsBack) ->
endYear = new Date().getFullYear()+1
label: year, value: year for year in [endYear - yearsBack .. endYear]
编译成这个脚本:
yearSource = function(yearsBack) {
var endYear, year, _i, _ref, _results;
endYear = new Date().getFullYear() + 1;
_results = [];
for (year = _i = _ref = endYear - yearsBack; _ref <= endYear ? _i <= endYear : _i >= endYear; year = _ref <= endYear ? ++_i : --_i) {
_results.push({
label: year,
value: year
});
}
return _results;
};
这将返回从给定年份向前的年份列表。
在部署了重新编译脚本的更新后,脚本突然如下所示:
yearSource = function(yearsBack) {
var endYear, year;
endYear = new Date().getFullYear() + 1;
return {
label: year,
value: (function() {
var _i, _ref, _results;
_results = [];
for (year = _i = _ref = endYear - yearsBack; _ref <= endYear ? _i <= endYear : _i >= endYear; year = _ref <= endYear ? ++_i : --_i) {
_results.push(year);
}
return _results;
})()
};
};
由于该列表应该是 jQuery UI 自动完成小部件的来源,这彻底破坏了事情。
我可以通过将循环工作移动到新的缩进行来修复它:
yearSource = (yearsBack) ->
endYear = new Date().getFullYear()+1
for year in [endYear - yearsBack .. endYear]
label: year, value: year
我做错了什么导致咖啡脚本版本之间出现问题?