I have a problem that when testing my classes using Jasmine, some properties of an inherited class get garbage initial values despite the fact I initialize them in the parent class.
To be precise: I have a "class"
function Attributes(attr) {
...
}
which is then to be used as a property inside another "class"
function Tag(){
this.attr = new Attributes();
}
When I instantiate the Tag class
var tag = new Tag();
everything is OK, no garbage is inside tag.attr property. Then I create a child class
function Div(){
...
}
Div.prototype = new Tag();
And here it is that the problem appears: in a browser I see that when I instantiate Div class
var div = new Div();
its div.attr property (inherited from Tag) has expected values. But the same code in Jasmine yields that div.attr contains garbage values inside. Note that Attribute class has no uninitialized properties. What it can be and how to get rid of this? For the moment, I have to include this.attr = new Attributes(); in Div class as well, but this approach ruins the idea of inheritance.
P.S. Additional info. As it was mentioned before, in browser the code works very well. The problem appears in Jasmine. For example, this TDD code
describe('inherited objects should have proper values', function(){
it('creates odd objects', function(){
var attr = new Attributes(),
tag = new Tag(),
div = new Div();
expect(attr.width).toBe(undefined);
expect(tag.attr.width).toBe(undefined);
expect(div.attr.width).toBe(undefined);
});
});
produces an error only on the last expect:
Expected 15 to be undefined.
while the others are passing perfectly.