The question isn't entirely off-topic.  The type of code you're writing
affects the style of code you write.  In particular prototype based objects
are one of the techniques to make async callbacks organized.

On howtonode, I've written a few articles explaining the various OOP
techniques in JavaScript.

http://howtonode.org/object-graphs
http://howtonode.org/object-graphs-2
http://howtonode.org/object-graphs-3

More recently, I wrote an article about reading and parsing linux device
files.  The article is written using vanilla callbacks.  At the end, I
convert it to OOP style using constructor+prototype.

http://nodebits.org/linux-joystick

Also I'll note that constructor+prototype is *very* fast in V8.  The
closure factory style is nice in event based code because you don't need to
worry about binding "this" as is often a problem with passing callbacks
around.


On Tue, Apr 17, 2012 at 6:53 AM, Scott Ware <[email protected]> wrote:

> Hello, Node.js community!
>
> I've been using Node.js for about 8 months now, and have been constantly
> learning as much as I can about it as well as bettering my knowledge on JS
> as well. Its a fantastic product, and can't remember the last time I had
> this much fun hacking away at things!
>
> My question is in regards to OOP: Is there a "standard" or specific method
> that most of the community uses or is it mainly all just personal
> preference? I've been browsing as much code as I can on Github, looking at
> the different methods and what not. Such as Pseudo-classical, Prototypal,
> etc.
>
> Currently I include this in my constructor(s):
>
> function Tester(name) {
>   if (!(this instanceof Tester)) {
>     return new Tester(name);
>   }
>
>   this.name = name;
> }
>
> Tester.prototype.say = function () {
>   console.log('Hello, ' + this.name);
> }
>
> var person = new Tester('Scott');
> person.say();
>
> To that, I have read the "Good Parts" book and some others, and also
> wonder if there is a style that's preferred based on certain methods or
> use-cases that might be deprecated or soon will be? Like getting away from
> the using 'new' style of coding.
>
> Sorry if this is such a n00b question. When I write code, programs, I just
> want to make sure that I have done my research and am doing it the right
> way, vs a "wrong?" way.
>
> Thanks all, in advance!
>
> --
> Job Board: http://jobs.nodejs.org/
> Posting guidelines:
> 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 post to this group, send email to [email protected]
> To unsubscribe from this group, send email to
> [email protected]
> For more options, visit this group at
> http://groups.google.com/group/nodejs?hl=en?hl=en
>

-- 
Job Board: http://jobs.nodejs.org/
Posting guidelines: 
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 post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en

Reply via email to