I’m basically trying to create a generic object in javascript that I can use to act like an associative array.
But I would like to give the object some custom members to be able to operate on the giving object. Needles to say I’m failing miserably hopefully someone can point me in the right direction.
Here is the generic object I’m talking about.
function easeArray() {
this.valIndex = function(searchTerm,object) {
//searchTerm+object;
if (searchTerm in object) {
return "true" + object[searchTerm]
}
}
}
So then I try to initialize it like this.
var myCollection = new easeArray();
myCollection = {"dioxanes": 0, "shunning": 1, "plowed": 2,
"hoodlumism": 3, "cull": 4, "learnings": 5,
"transmutes": 6, "cornels": 7, "undergrowths": 8,
"hobble": 9, "peplumed": 10, "fluffily": 11,
"leadoff": 12, "dilemmas": 13, "firers": 14,
"farmworks": 15, "anterior": 16, "flagpole": 17};
this works fine but when I try to do something like this:
alert(myCollection.valIndex())
I get an error. Type Error: object does not support property or method.
Never mind that I’m not passing the values into the function I understand that, the function is not even recognize.
My end result is to have a generic object that i can initialize and fill up with key value pairs and then simply say object.valindex("searchTerm");
Any help would be greatly appreciated.
This cannot work because on latest statement you destroy the instance of your
easeArrayobject. Thus the array has not such method definedtry this code instead