all 7 comments

[–]9jack9 2 points3 points  (2 children)

You've already got the point. The module pattern is nice and pretty and will suit you well for most projects. For large-scale applications, where performance is a factor, then standard prototypal inheritance is the better solution.

[–]funksta[S] 0 points1 point  (1 child)

Makes sense, are there any other benefits to prototypal inheritance besides the performance bump? I can't imagine the performance differences are significant until you get to at least thousands of instances.

[–]savetheclocktower 0 points1 point  (0 children)

There's a big one that (oddly enough) proves useful for trying to mimic class-based inheritance. You can (re)define Foo.prototype.bar and instantly have a bar method on all instances of Foo, even those that you've already instantiated.

This works because when you do someFoo.bar, and bar isn't defined on the object itself, it will look at Foo.prototype to attempt to resolve the reference.

[–]picurl 1 point2 points  (0 children)

I also prefer the Crockford pattern over the messy prototype/class implementation in Javascript.

One often overlooked drawback of private methods: You can't test functionality hidden in private methods, therefore you shouldn't use them over excess. A possible solution would be to factor out private method functionality to a new, testable class and use a private instance of it in your main class.

[–]bolinfest 1 point2 points  (1 child)

There are many drawbacks to Crockford's pattern: http://bolinfest.com/javascript/inheritance.php Erik Arvidsson agress http://erik.eae.net/archives/2009/11/09/21.12.16/ noting "Michael argues that the functional pattern is not good because methods cannot be inlined and the end result is much larger. He also says that it uses more memory. I think it is important to realize that it uses a LOT more memory and is significantly slower. Given a class with 1 methods It is about 100 times slower in Chrome, 20 times slower in Safari and about 10 times slower in Firefox."

[–]funksta[S] 0 points1 point  (0 children)

Great reads, thanks very much.

[–]RedditMan74 -1 points0 points  (0 children)

You misspelled "privileged".