In Loop through a 'Hashmap' in JavaScript I saw recommendation to use 'for' loop to go via elements of hash collection. I implemented that, but the following code:
function MyClass(objs)
{
var _objs = objs;
this.showNames = function () {
var s = "Names: ";
for (var obj in _objs) {
s += obj.getName();
}
console.log(s);
};
}
function MyObj(name)
{
var _name = name;
this.getName = function () { return _name; };
}
var mc = new MyClass({ 'M': new MyObj("morning"), 'D': new MyObj("Day") });
mc.showNames();
gives error:
Uncaught TypeError: obj.getName is not a function
What am I doing wrong?
Thanks!