News for hackers. Stuff that matters.
Re:Encapsulation in Javascript by rondale_sc on Tuesday September 13, 2011 @11:49AM (#2991972)
Yes I suppose that's true. I think it all depends on what your case is and preference, but yes memory is an issue with the module method. Just out of curiosity what are the best tools out there to test memory consumption of javascript snippets? It'd be interesting to see prototype/module/whatever_else memory usage side by side.
Re:Encapsulation in Javascript by jashkenas on Tuesday September 13, 2011 @12:40PM (#2992203)
The browsers are getting better at optimizing memory use for small closures all the time, but there's still a long way to go. Here's a screenshot of the Chrome heap profiler for both cases:

http://cl.ly/A5NX

Re:Encapsulation in Javascript by mun2mun on Tuesday September 13, 2011 @04:07PM (#2993287)
I have one question. How to handle private methods in prototype/module pattern? If I declare private function in obj function declaration I can not access it in public functions attached to the prototype of obj. This is also true for module pattern. This problem arises when I need to add extra method later. How to overcome this situation?
Re:Encapsulation in Javascript by asolove on Tuesday September 13, 2011 @12:20PM (#2992125)
You can use a heap snapshot in Chrome Dev Tools. It has a handy feature where you take multiple snapshots and it shows you the differences in memory usage between them. See: http://code.google.com/chrome/devtools/docs/heap-profiling.h...
Re:Encapsulation in Javascript by rondale_sc on Tuesday September 13, 2011 @03:11PM (#2993003)
I'll definitely be looking into that. Thanks.