This has nothing to do with Node. The disparity in patterns you're seeing
is in language experience. "bean1.js" and "bean3.js" are just explicitly
doing what "bean2.js" does for implicitly: allocate an instance object.
"bean4.js" is not a comparable pattern to 1, 2 and 3 in the initialization
sense: it's an instance of the built-in Object whose properties are being
used to expose multiple "exports", whereas 1, 2, 3 use a function to export
a single function object "export".

Rick

On Tue Jan 06 2015 at 7:23:11 PM Prabhash Rathore <prabhashrath...@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)?
>
> 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 : '';}
>
>  --
> 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+unsubscr...@googlegroups.com.
> To post to this group, send email to nodejs@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/nodejs/85a3bdc4-83af-4c8a-979d-5d527eee8695%40googlegroups.com
> <https://groups.google.com/d/msgid/nodejs/85a3bdc4-83af-4c8a-979d-5d527eee8695%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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+unsubscr...@googlegroups.com.
To post to this group, send email to nodejs@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/nodejs/CAHfnhfqiTZ5MCoavQ6Ybj2iA%3DkoC-WQoGugrZJpp%2BmJ6ewvZ4g%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to