Troubles using defining a method for an object

时间:2018-09-19 08:21:21

标签: javascript

I'm having troubles trying to define a method of an object. I think the problem is that I'm using sounds[i]. I know I can do this without a loop, but I want to learn how to do this simpler. I also tried using this to refer to sounds[i] but it didn't work.

var sound_files = ["b_kickdrum.wav", "p_snare.wav", "ts_hitat.wav",
                   "b_kickdrum_rev.wav", "p_snare_rev.wav", "ts_hitat_rev.wav", 
                   "lok.wav"]

var sounds = new Array(7);

for (i  = 0; i < sound_files.length; i++) {
    sounds[i] = new XMLHttpRequest();
    sounds[i].open("Get",sound_files[i],true);
    sounds[i].responseType = "arraybuffer";
    var sound = sounds[i];
    sounds[i].onload = function(){
        context.decodeAudioData(sounds[i].response, function(buffer){buffers[i] = buffer;});
    }
    sounds[i].send();
}

0 个答案:

没有答案