I just read this article http://javascriptweblog.wordpress.com/2011/05/31/a-fresh-look-at-javascript-mixins/.
In the section entitled “#4 Adding Caching” it says:
By forming a closure around the mixins we can cache the results of the initial definition run and the performance implications are outstanding.
I don’t understand how this works– how does using the module pattern here lead to a faster/cached version of the code?
basically, without using the closure, the mixin function will be created every
time the mixin is used. By creating a closure, each of the function will be
created once, and the mixin will reference those functions every time it is
called. Since the mixin doesn’t have to recreate those functions every time it
runs, its faster.
without the closure
with the closure