Does calling a function take the same resources and time, as creating an instance of the constructor function in javascript node v8.5.0?
I find that they give me the same result, as:
var repo = function () {
var db = {};
var get = function (id) {
console.log('Getting task ' + id);
return {
name: 'new task from db'
}
}
var save = function (task) {
console.log('Saving ' + task.name + ' to the db');
}
console.log('newing up task repo');
return {
get: get,
save: save
}
}
module.exports = repo();
When I replace module.exports = repo();
with module.exports = new repo;
it gives me the same result, but I need to know which one is better performance wise.