this.property is undefined: Cannot read property 'classList' of undefined
<p>I'm making something to <strong>visualize photographs</strong>.<br>
The goal is to select the picture you want in the "list" to make it appear on the main HTML element. But to help you find where you are in the list there's a class putting borders on the element you selected.</p>

<p><strong>The issue :</strong><br>
The function executing with the event <code>this.block.onclick = function ()</code> begins well, the <code>.selected</code> is removed from the initial selected element, but when comes <code>this.block.classList.add('selected');</code> I get this error:</p>

<blockquote>
  <p>media_visu.js:26 Uncaught TypeError: Cannot read property 'classList' of undefined</p>
</blockquote>

<p>I tried to put the <code>function</code> outside, tried <code>className</code>, <code>setAttribute</code>, but nothing changed: my <code>this.block</code> seems to be <code>undefined</code>.</p>

<p><strong>mediavisu.js :</strong></p>

<pre><code>var mediaVisu = function () {
    'use strict';

    window.console.log('mediaVisu loaded');




    var i,
    visu = document.querySelector("#img"),
    Album = [];

    function Photo(nb, folder) {
        this.block = document.querySelector("#list_img_" + nb);
        this.place = 'url(../src/' + folder + '/' + nb + '.jpg)';
        this.block.onclick = function () {
            for (i = 0; i &lt; Album.length; i += 1) {
                window.console.log(Album[i].block);
                if (Album[i].block.classList.contains('selected')) {
                    Album[i].block.classList.remove('selected');
                }
            }
            visu.style.background = this.place;
            window.console.log(visu.style.background);
            window.console.log(this.place);
            this.block.classList.add('selected');
        };
        Album[Album.length] = this;
    }

    var test_a = new Photo(1, "test"),
    test_b = new Photo(2, "test"),
    test_c = new Photo(3, "test"),
    test_d = new Photo(4, "test"),
    test_e = new Photo(5, "test");

    window.console.log(Album);
    for (i = 0; i &lt; Album.length; i += 1) {
        window.console.log(Album[i]);
    }
};
</code></pre>