It might be a wiki question, but still. Which approach conforms more to the Javascript spirit:
var Report = function(data) {
var that = this;
that.send = function() { ... };
};
var r = new Report(data); // create and validate the data
r.send(); // encode and send the data
or
var sendReport = function(data) {
...
// create, validate, encode and send the data
...
};
The first approach seems to be more OO, the second more functional? In the first it might seem that the functions of Report
are more testable (though for example we have only send()
at this stage). Also, I like to see object of type Report
in debugger when required to examine the state.
The second approach might be more "simple", but it seems to be less testable.
I am personally with the first approach, but the question is if I try to apply the OO "principles" in the "wrong" domain (please help me to word my question better).