I have a scenario where my code retrieves a list of JavaScript objects as JSON via AJAX. These objects are then parsed using JSON.parse and stored in a variable.
var myListOfObjects = [
{"id":1,"Name":"John","xcoord":23.7,"ycoord":37.2},
{"id":2,"Name":"Mary","xcoord":17.7,"ycoord":54.6},
....
];
I'm trying to figure out the most efficient way to associate the same method with each of these objects, so that the method can be easily called during iteration:
myListOfObjects.forEach( function(person){
console.log( person.getDistance() );
} );
One approach could be to define the parameter within each iteration, but this doesn't seem to be the most efficient method. Also, implementing this with d3js might be challenging as it would require reiterating over the list before binding it to a DOM selection.
Any suggestions or insights would be greatly appreciated.