There is nothing wrong with not using the prototype and preferring a
functional style.
There is something wrong with using closure scope when you can use `this`
For example
function fooFactory(bar) {
return {
baz: function () { return bar }
}
}
function fooFactory(bar) {
return {
bar: bar,
baz: baz
}
}
function baz() { return this.bar }
Note that here we are re-using a single function and accessing state
through this rather then closures. This reduces the number of functions in
memory and reduces the function creation overhead. The trick is to not
create functions if possible.
On Tue, Jun 19, 2012 at 7:41 PM, Rich Schiavi <[email protected]> wrote:
>
> Anyone out there have any deep benchmarks to back up using prototype/new
> over a functional style in Node/V8? And that it is a clear
> performance/memory win??
>
> Mixu's node book says:
>
> http://book.mixu.net/ch6.html
>
> "Don't construct by returning objects - use prototype and new"
>
>
> The claim to functional being "terrible" is one I question, since I've
> done some basic comparisons between a functional style versus
> prototype/new in node and seen nothing to indicate it's "terrible" to use
> functional style.
>
> (The benefit of altering a prototype chain dynamically to change all
> instances of a class isn't something I particularly am concerned with; so
> more focused on performance and clean design of code), and I particularly
> like Crockford's approach, as it induces engineers to think more
> functionally, and javascripty and less java/class new Foo(),etc.
>
> Thanks,
>
> Rich
>
> --
> 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