Domanda

Guarda questo codice:

        var Test = {
        options: {
            name: 'foo'
        },
        name: 'foo',
        init: function (name) {
            this.name = name;
            this.options.name = name;
        }
    };

    var dict = {};

    for (var i = 0; i < 3; i++) {
        var obj = Object.create(Test);
        obj.init(i);
        dict[i] = obj;
    }

Non capisco perché tutte le proprietà in dict [x] .options.name nell'oggetto DICT hanno lo stesso valore (2) e le proprietà dict [x]. Name ha un valore diverso?

Nessuna soluzione corretta

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top