2014-02-15 16 views
0

我有這樣的CoffeeScript代碼推到一個列表

emails = [] 
    for mail in profile.emails 
     emails.push mail.value 
    if !emails[0] 
     options = 
      url: "https://api.github.com/user/emails?access_token=" + accessToken 
      headers: 
       "user-agent": "zmgc.net" 
       Accept: "application/vnd.github.v3" 
     request options, (error, response, body)-> 
      unless error 
       try 
        user_emails = JSON.parse body 
        email = user_emails[0].email 
        console.log email 
        emails.push email 
       catch ex 
        return done(ex) 

當我進入if !emails[0],並試圖將值推到郵件列表中,我得到一個空字符串時,沒有得到結果!

我錯過了什麼?

回答

0

該調用是異步的,所以在我的代碼中這是最後一次,這就是爲什麼我無法得到它。它現在是固定的。