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 : '';
}On Jan 6, 2015, at 7:19 PM, Prabhash Rathore <prabhas...@gmail.com> wrote: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)
//bean4.js module.exports = { name : ''; department : ''; }
--
Job board: http://jobs.nodejs.org/
New group rules: https://gist.github.com/othiym23/9886289#file-moderation-policy-md
Old group rules: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
---
You received this message because you are subscribed to the Google Groups "nodejs" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nodejs+un...@googlegroups.com.
To post to this group, send email to nod...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/nodejs/85a3bdc4-83af-4c8a-979d-5d527eee8695%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
module.exports = {
name : '';
department : '';
}--
Job board: http://jobs.nodejs.org/
New group rules: https://gist.github.com/othiym23/9886289#file-moderation-policy-md
Old group rules: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
---
You received this message because you are subscribed to the Google Groups "nodejs" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nodejs+un...@googlegroups.com.
To post to this group, send email to nod...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/nodejs/5bb7cb17-c993-4164-bf2b-67bdbea1d647%40googlegroups.com.
module.exports = function Car (name, cost, mpg, alternative) {
this.name = name;
this.cost = cost;
this.env_damage = mpg;
this.alternative = alternative;
};
Car.prototype.appeal = function() {
return(this.cost/this.mpg);
};
Car.prototype.snark = function() {
return(this.alternative.advise());
};
module.exports = function Car (name, cost, mpg, alternative) {
var api = {
name: name,
cost: cost,
env_damage: mpg,
alternative: alternative,
appeal: function appeal () { api.cost / api.mpg; },
snark: function snark () { api.alternative.advise(); }
};
return api;
};
--
Job board: http://jobs.nodejs.org/
New group rules: https://gist.github.com/othiym23/9886289#file-moderation-policy-md
Old group rules: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
---
You received this message because you are subscribed to the Google Groups "nodejs" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nodejs+un...@googlegroups.com.
To post to this group, send email to nod...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/nodejs/6CC0F73D-A104-487B-83F6-0930105B236C%40g8o.net.
To view this discussion on the web visit https://groups.google.com/d/msgid/nodejs/CAN5%2BLUuVpyXqF-SfGjBF_WuRR5LqN4LTAZQ77%3DseQjtiAY-VmQ%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/nodejs/CAPJ5V2ZLG9FzH2GK%2BxxGn6c8-bXFZR8iDWVyNbh0RXEhR_qy7g%40mail.gmail.com.
appeal: appeal,
snark: snarkwith something like appeal: function () { return appeal(api); },
snark: function () {return snark(api); }--
Job board: http://jobs.nodejs.org/
New group rules: https://gist.github.com/othiym23/9886289#file-moderation-policy-md
Old group rules: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
---
You received this message because you are subscribed to the Google Groups "nodejs" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nodejs+un...@googlegroups.com.
To post to this group, send email to nod...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/nodejs/1581449.3jv6NryCTy%40homer.
function Car(name, cost, mpg, alternative) {
var _x = 5;
this.getX = function () { return _x; };
this.name = name;
this.cost = cost;
this.env_damage = mpg;
this.alternative = alternative;
}
(new Car()).getX(); function closureCar(name, cost, mpg, alternative) {
var _x = 5;
return {
getX: function () { return _x; },
name: name,
cost: cost,
env_damage: mpg,
alternative: alternative
};
}
closureCar().getX();