누군가이 coffescript의 while 루프에서 증분 i ++가 자바 스크립트로 변환 될 때 while 루프 외부에 배치되는 이유를 설명 할 수 있습니까? 여기 커피 스크립트에서 while 루프를 만드는 방법
if eventtype is 'test'
i = 0
while i < platforms.length
$.ajax
url: 'myurl/?id=567&platform='+platforms[i]
.done (response) ->
if platforms[i] is 'tv'
$scope.lolVdatatv = JSON.parse(response)
alert response
if platforms[i] is 'phone'
$scope.lolVdataphone = JSON.parse(response)
alert response
if platforms[i] is 'internet'
$scope.lolVdatainternet = JSON.parse(response)
alert response
i++
변환 된 자바 스크립트입니다 : 이것은 while 루프가 종료되지 일으키는
var i;
if (eventtype === 'test') {
i = 0;
while (i < platforms.length) {
$.ajax({
url: 'myurl/?id=567&platform='+platforms[i]
}).done(function(response) {
if (platforms[i] === 'tv') {
$scope.lolVdatatv = JSON.parse(response);
alert(response);
}
if (platforms[i] === 'phone') {
$scope.lolVdataphone = JSON.parse(response);
alert(response);
}
if (platforms[i] === 'internet') {
$scope.lolVdatainternet = JSON.parse(response);
return alert(response);
}
});
}
i++;
}
.
들여 쓰기 문제 : 당신은
while
루프 내부에있을 더 들여 쓰기i++
문이 필요합니다. coffeescript에'i ++'뒤에 2 칸을 더하십시오. – Brian이전에 2 칸 추가 하시겠습니까? 실제로 while 루프에서 증가량을 배치했지만 _results.push (i ++)로 변환되는 이유는 무엇입니까? – Milligran
새로운 질문이있는 경우 업데이트하십시오. 그리고 들여 쓰기를 정상화하십시오 – Alexander