Я пытаюсь использовать простое наследование от http://ejohn.org/blog/simple-javascript-inheritance/, и у меня есть следующий код:
var resources = [];
var Entity = Class.extend({
pos : {
x: 0,
y: 0
},
init : function(x, y) {
this.pos.x = x;
this.pos.y = y;
},
toString : function() {
return this.pos.x + ' | ' + this.pos.y;
}
});
var bFunc = Entity.extend({
init : function(x, y) {
this._super(x, y)
}
});
var cFunc = Entity.extend({
init : function(x, y) {
this._super(x, y)
}
});
var Func = Class.extend({
init : function() {
this.b = new bFunc(1, 10);
resources.push(this.b);
this.c = new cFunc(5, 10);
resources.push(this.c);
},
print : function() {
for(var i in resources) {
console.log(resources[i].toString());
}
}
});
var func = new Func();
func.print();
Когда я запускаю вышеупомянутое, я вижу это в консоли:
5 | 10
5 | 10
Но я настроен:
this.b = new bFunc(1, 10); // 1, 10
resources.push(this.b);
this.c = new cFunc(5, 10); // 5, 10
resources.push(this.c);
Почему я не получаю следующее?
1 | 10
5 | 10