I recently started programming in JavaScript (Server side) and Node.js. I come from Java background where there is a concrete standard on how you define Data Object, which is Java Bean. Do we have any such standards in JavaScript/Node on how we define Data Objects (similar to Java Beans)?
I have researched at many places and couldn't find any standards. I have seen following styles but not sure which is better or recommended:
//bean1.js
module.exports = function() {
var obj = {};
obj.name = '';
obj.department = '';
return obj;
}
//bean2.js
module.exports = function() {
this.name = '';
this.department = '';
return this;
}
//bean3.js
module.exports = function(param) {
var obj = {};
if(param === undefined) {
return obj;
}
obj.name = param.name;
obj.department = param.department;
return obj;
}
//bean4.js
module.exports = {
name : '';
department : '';
}