2017-10-04 67 views
0

我有一個關於這個小Javascript程序的行5的問題。使用行5,audioNumber上的括號/參數位於內部圓括號的內部/旁邊,因爲audioNumber.indexOf的參數。鑑於此行上的編號爲1的參數爲.splice,因此它位於外部圓括號內。這是正確的理解爲什麼audioNumber1是他們在哪裏行5Javascript - 關於嵌套括號/參數

function playAudio(audioNumber) { 
    var audio = document.getElementById('sound' + audioNumber); 
    audio.play(); 
    var nonPlaying = [1, 2, 3, 4, 5, 6, 7]; 
    nonPlaying.splice(notPlaying.indexOf(audioNumber), 1); // line 5 
    nonPlaying.forEach(function(id) { 
    document.getElementById('sound' + id).pause(); 
    document.getElementById('sound' + id).currentTime = 0; 
    }); 
}; 
+1

是的,這是一個正確的理解 –

+0

嚴格地說,那些是參數,而不是參數:https://stackoverflow.com/questions/156767/whats-the-difference-between-an-argument-and-a-parameter – JLRishe

+0

謝謝各位的意見。 – Emma45

回答

0

的接合方法可以與2個參數被使用:起始索引和元件的數量來刪除:

array.splice(start, deleteCount) 

在「audioNumber」是IndexOf方法的參數:

notPlaying.indexOf(audioNumber) 

... indexOf方法返回的結果是拼接方法中的第一個參數('start'參數),而值'1'是拼接方法中的第二個參數('deleteCount'參數)。

+0

謝謝海蒂,這是一個很好的,徹底的解釋。 – Emma45

0

是的,沒錯!但有一點區別,這些參數不是參數。