I used to mostly do this:
class Person
constructor : (@parent, @data)->
@index = @parent.length
class People
constructor : ->
people = []
for data in database.people
people.push new Person(people, data)
Lately I have been trying the following:
class Person
constructor : (@data)->
pushTo : (list)->
this.index = list.length
list.push this
class People
constructor : ->
people = []
for data in database.people
person = new Person(data)
person.pushTo people
So was wondering if there is any cons about doing it the second way. The reason I am asking is that it might not be the responsibility of Person to add himself to the list.