Possible Duplicate:
Javascript infamous Loop problem?
for (var i=0; i<songList.length; i++){
        test.init({
        });
}
var test = {
    init: function (params) {
        var my = this;
        var backend = WaveSurfer.Audio;
        if (!params.predrawn) {
            backend = WaveSurfer.WebAudio;
        }
        var id = playList.length;
        this.id = id;
        this.backend = Object.create(backend);
        this.backend.init(params);
        this.drawer = Object.create(WaveSurfer.Drawer);
        this.drawer.init(params);
        this.backend.bindUpdate(function () {
            my.onAudioProcess();
        });
        this.bindClick(params.canvas, function (percents) {
            my.playAt(percents);
        });
    playList.push(my);
When I debug this script: my id is 0 for the first element; but when I go into the second loop suddenly both ids become 1. How is this possible?

 
     
    