Just a quick thought, of which I have no idea how to google it.
If you get a list of lets say 'persons' from an API in JSON format with AngularJS and you convert it to a JS array/object:
[
{firstName: 'Foo', lastName: 'Bar'},
{firstName: 'Banana', lastName: 'Fruit'}
]
And you want some general function that joins first and last name into fullName.
Is it then generally considered better to use solution 1 or 2?
Solution 1 Array consists of objects which have all methods they need inside themself.
[
{firstName: 'Foo', lastName: 'Bar', fullName: function(){return this.firstName+' '+this.lastName;}},
{firstName: 'Banana', lastName: 'Fruit', fullName: function(){return this.firstName+' '+this.lastName;}}
]
I think this is the most OOP solution, but is in also the best solution in case of Javascript (and long lists)?
Solution 2 Make helper function that's only being instantiated once.
var helper = function(person)
{
return person.firstName+' '+person.lastName;
}
I know this is very basic, but sometimes that is the best stuff to get right ;)