Is there a standard way of finding all the instances of a Javascript object as well as finding a particular instance by id? As an example:
function person(fnm, lnm) {
this.firstname = fnm;
this.lastname= lnm;
}
var personObj1 = new person('john', 'smith');
var personObj2 = new person('jane', 'jones');
Is there a method of cycling through all the new person objects? I can do it if I create a public object and use it as an associative array for storing all the new person objects, by a unique id:
var persons = new Object();
function person(fnm, lnm) {
this.firstname = fnm;
this.lastname= lnm;
persons[fnm + lnm] = this;
}
Even though this allows me to find all the instances of the object, and allows a lookup of the object by ID it doesn't seem either elegant or self contained.
Any input appreciated.
Start Free Trial