Inheritance and Object.Create in Javascript
-
30-10-2019 - |
Question
look at this code :
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;
}
i don't understand why all the properties in dict[X].options.name in the object dict has the value same value(2) and the propertiesin dict[X].name has different value ?
No correct solution
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow