Advertisement

08.25.2008 at 03:07AM PDT, ID: 23674818 | Points: 500
[x]
Attachment Details

Finding All Instances of a Javascript Object

Asked by ralphcarey in JavaScript

Tags: ,

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
[+][-]08.25.2008 at 07:08AM PDT, ID: 22305563

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]08.25.2008 at 09:45AM PDT, ID: 22306980

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]08.25.2008 at 09:52AM PDT, ID: 22307031

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]08.25.2008 at 02:32PM PDT, ID: 22309428

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]08.25.2008 at 03:36PM PDT, ID: 22309956

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]08.25.2008 at 03:42PM PDT, ID: 22310001

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]08.25.2008 at 03:57PM PDT, ID: 22310105

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20081112-EE-VQP-42 / EE_QW_2_20070628