2011-12-18 111 views
0

我有一個函數作爲參數此代碼殺死頁面

# parameters for hour tickmarks 
@firstHour = (t) -> 
    msPerHour = 1000*60*60 
    Math.floor(t/msPerHour) * msPerHour 

@nextHour = (currentHour) -> 
    msPerHour = 1000*60*60 
    currentHour + msPerHour 

時稱爲這樣

marks = markMaker.makeMarks(@firstMonth, @nextMonth, @classifier) 

makeMarks: (first, nextIncrement, classifier) -> 
    results = new Array() 

    t = first(@minT) 
    while t<[email protected] 
     mark = 
      t: t 
      x: this.tToX(t) 
      class: classifier(t) 

     results.push(mark) 

     t = nextIncrement(t) 

    results 

此功能的偉大工程,具有以下兩個功能我們問題:

# parameters for month tickmarks 
@firstMonth = (minT) -> 
msPerDay = 1000*60*60*24 
t = Math.floor(minT/msPerDay) * msPerDay 
d = new Date(t) 
while(d.getDate() isnt 0) 
     t += msPerDay 
     d.setTime(t) 
t 

@nextMonth = (currentMonth) -> 
msPerDay = 1000*60*60*24 
t = currentMonth + msPerDay 
d = new Date(t) 
while(d.getDate() isnt 0) 
     t += msPerDay 
     d.setTime(t) 
t 

小時代碼工作正常,但月份代碼似乎並沒有終止。

+1

我不知道咖啡腳本的任何內容,但是當'd.getDate()'總是遞增時它會變成'0'嗎?這會是你的無限循環嗎? – 2011-12-18 20:40:32

回答

2

getDate函數永遠不會返回0.它的最小值是1,最大值是31.如果你正在尋找超出該範圍的任何東西,那就是等待一列未到的列車。