Suppose I have a DAO which touches the DB. Should the DAO return only data and then it's up to me to do the instantiation or is the DAO supposed to also do the instantiation and return me the instance - and why should I choose one method over another?// Example with instantiationstudentDAO = {  getById: function() {    const data = db.query('SELECT FROM `students`...');    return new Student(data);  }}// Example without instantiation (just returns the data)studentDAO = {  getById: function() {    const data = db.query('SELECT FROM `students`...');    return data;  }}
Are DAOs supposed to return instances or just their data?
design patterns
You should return the instance, because the purpose of the dao is to hide the database implementation from the rest of the code and your data object is specific to your db.In fact you should even avoid passing data into a constructor as in your example.eg.studentDAO = {    getById: function()     {         const data = db.query('SELECT FROM `students`...');        var s = new Student();        s.Id = data[0]:         //that data can be accessed like this and that element 0         //contains the student Id is information specific to the         //database and the responsibility of the DAO class NOT the         //Student class        return s;    } }