I have a bunch of JSON strings returned from an ajax call in a specific format, and when I start converting all of them into my own Javascript object, I begin to wonder if there is an even easier way, since we are talking about Javascript here.
I will have var manyOfThem = [ { name: 'a' }, { name: 'b' }, { name: 'c' } ];
And I would like to easily associate each of these objects with my functions so that I can do things like:
myClass.prototype.doSomething = function() {
};
$.each(manyOfThem, function(index, item) {
item.doSomething();
});
I think my concern is that I would not want (because its repetitive) to do this:
var myClass = function(item) {
this.name = item.name;
};
var oneOfThem = new myClass(manyOfThem[0]);
oneOfThem.doSomething();
Anyway, if there are reasons (security concerns?) Why I just need to suck them in and do it all manually, please share them, thanks!
source
share