I believed I had a good background in backbone.js but I have a problem I don't understand.
Suppose we have these two views:
BaseView = Backbone.View.extend({
foo: {},
initialize: function(options) {
this.render();
},
render: function() {
// ...
}
});
PageView = BaseView.extend({
render: function() {
this.foo.bar = 23;
}
});
If we check the attribute 'foo' in both views, obviously, it will be an empty object:
> BaseView.prototype.foo
Object {}
> PageView.prototype.foo
Object {}
But if we create a PageView instance, the 'foo' attribute from BaseView will be changed. How is that possible?
> page = new PageView()
> page.foo
Object {foo: 23}
> BaseView.prototype.foo
Object {foo: 23}
[Edit]
Actually, it's a general OOP question. In python:
class A(object):
foo = {}
class B(A):
def __init__(self):
self.foo['bar'] = 23
>>> print A.foo
{}
>>> b = B()
>>> print A.foo
{'bar': 23}