I
Ira
Hi, new to the group. I've been doing some object-oriented coding
with JavaScript.
What I've been using works, but if there's a better way, awesome.
I've got a prototype-defined method:
MyObj.prototype.equals = function(name) {
return (this.name == name);
}
And I've got an array of objects along with a lookup function that
returns an index for success, -1 for fail
var ObjArray = new Array();
Array.prototype.lookup_table = function(table_name) {
for (var i = 0; i < ObjArray.length; i++) {
if (this.equals(name)) {
return i;
}
}
return -1;
}
The problem (if you havent' noticed yet) is defining a general-purpose
lookup function for Arrays.
The next iteration of my code will probably have a sort of 'mother'
object that has an Array of objects as a member and then have the
lookup as a prototype of the mother-object unless I can think of a
better solution.
Any suggestion would be appreciated.
Cheers
with JavaScript.
What I've been using works, but if there's a better way, awesome.
I've got a prototype-defined method:
MyObj.prototype.equals = function(name) {
return (this.name == name);
}
And I've got an array of objects along with a lookup function that
returns an index for success, -1 for fail
var ObjArray = new Array();
Array.prototype.lookup_table = function(table_name) {
for (var i = 0; i < ObjArray.length; i++) {
if (this.equals(name)) {
return i;
}
}
return -1;
}
The problem (if you havent' noticed yet) is defining a general-purpose
lookup function for Arrays.
The next iteration of my code will probably have a sort of 'mother'
object that has an Array of objects as a member and then have the
lookup as a prototype of the mother-object unless I can think of a
better solution.
Any suggestion would be appreciated.
Cheers