2013-07-20 2 views
0

누군가이 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++; 
} 

.

+4

들여 쓰기 문제 : 당신은 while 루프 내부에있을 더 들여 쓰기 i++ 문이 필요합니다. coffeescript에'i ++'뒤에 2 칸을 더하십시오. – Brian

+0

이전에 2 칸 추가 하시겠습니까? 실제로 while 루프에서 증가량을 배치했지만 _results.push (i ++)로 변환되는 이유는 무엇입니까? – Milligran

+0

새로운 질문이있는 경우 업데이트하십시오. 그리고 들여 쓰기를 정상화하십시오 – Alexander

답변

1

Coffeescript는 python과 마찬가지로 들여 쓰기가 구분됩니다.

i = 0 
while i < platforms.length 
    //do things 
    i++ 
    //still inside. 
//this is outside of the loop 
+0

증분이 while 루프에 있고 배열 길이가 3입니다. 왜 조건절에 도달하기 전에 3 번 실행하는지 : while i

+0

@Milligran 당신이 묘사하는 것이 새로운 문제입니다. 이미 한 가지 질문에 답한 한 사람을 전체 작업으로 끌어 오지 말고 새로운 문제에 대해 새로운 좋은 질문을 던지십시오. – millimoose

관련 문제