I have my custom class and I want to store it into map collection, but while I want to get one of the value from the map (one instance of my object) I got error that object is undefined. Is there any possibility to cast object or something? If I push simple string instead of object of my custom class everything is ok. Someone can tell me how to solve this problem? Of course if this problem could be solved.
js:
function CustomClass(first, second, third){
this.one = first;
this.two = second;
this.three = third;
}
CustomClass.prototype.constains(obj1, obj2){}
...
var dictionary = new Object();
dictionary[key] = CustomClass(1, "lel", 2);
for(var el in dictionary) //here IE debugger shows that I have a right key, but the value is undefined.
{
if(dictionary[el].contains(something))
{...}
}
If it depends I use IE10. Thanks for help and also for tips!
edit:
If I use
dictionary[key] = new CustomClass(1, "lel", 2);
instead of:
dictionary[key] = CustomClass(1, "lel", 2);
it works, but someone could tell me why, something like this:
dictionary[key] = "lel";
works without new operator? From what I know everything in js is an object so what's the difference beetwen inserting a string and a custom class? (I'm new in js, so sorry for my bad knowledge)
newto callCustomClass, can you post a demo to reproduce the issue? Try jsfiddle.netvar elem[key] =doesn’t look rightelem? You haven't declared that. Also, as David says, you shouldn't usevarin front ofelem[key] =