I just went to http://jsperf.com开发者_开发问答/prototype-vs-closures/2 prototype vs closures performance test. Actually I use Modular pattern a lot which internally uses clousre AFAIK. Now as per test it says protoype wins over modular pattern. Is that true? should I be using prototypes based approach whenever it is possible?
Look at the diagram and think whether you reach a couple 100k reads / writes. If not: irrelevant for you, take the approach which feels most natural and maintainable to you.
Clean code is far more important than optimization, and premature optimiztion causes much grief later on.
Also, it is quite possible that the differences are much smaller a couple of JavaScript Enigne revisions (a couple of months) later...
The test you've linked to has no relation to the module pattern; Rather, it tests prototype-based methods vs closure-based methods on an object. (Crockford's "privileged" methods.)
精彩评论