<?xml version="1.0" encoding="utf-8"?>
<feed xml:lang="en-us" xmlns="http://www.w3.org/2005/Atom"><title>Simon Willison's Weblog: modulepattern</title><link href="http://simonwillison.net/" rel="alternate"/><link href="http://simonwillison.net/tags/modulepattern.atom" rel="self"/><id>http://simonwillison.net/</id><updated>2009-04-30T19:59:39+00:00</updated><author><name>Simon Willison</name></author><entry><title>Why I don't love JavaScript's Module Pattern</title><link href="https://simonwillison.net/2009/Apr/30/module/#atom-tag" rel="alternate"/><published>2009-04-30T19:59:39+00:00</published><updated>2009-04-30T19:59:39+00:00</updated><id>https://simonwillison.net/2009/Apr/30/module/#atom-tag</id><summary type="html">
    
&lt;p&gt;&lt;strong&gt;&lt;a href="http://snook.ca/archives/javascript/no-love-for-module-pattern"&gt;Why I don&amp;#x27;t love JavaScript&amp;#x27;s Module Pattern&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;
Jonathan Snook points out that the module pattern (where private functionality is hidden in a closure and only public methods are revealed to outside scopes) makes code a lot harder to debug. I use the module pattern for pretty much everything, not because I want to keep stuff private but more to avoid any chance of leaking out in to the global namespace. If I need to debug a value I temporarily assign it as a property on the global window object.


    &lt;p&gt;Tags: &lt;a href="https://simonwillison.net/tags/closures"&gt;closures&lt;/a&gt;, &lt;a href="https://simonwillison.net/tags/debugging"&gt;debugging&lt;/a&gt;, &lt;a href="https://simonwillison.net/tags/javascript"&gt;javascript&lt;/a&gt;, &lt;a href="https://simonwillison.net/tags/jonathan-snook"&gt;jonathan-snook&lt;/a&gt;, &lt;a href="https://simonwillison.net/tags/modulepattern"&gt;modulepattern&lt;/a&gt;&lt;/p&gt;



</summary><category term="closures"/><category term="debugging"/><category term="javascript"/><category term="jonathan-snook"/><category term="modulepattern"/></entry><entry><title>Module Pattern Provides No Privacy... at least not in JavaScript(TM)</title><link href="https://simonwillison.net/2008/Jun/27/peters/#atom-tag" rel="alternate"/><published>2008-06-27T19:01:34+00:00</published><updated>2008-06-27T19:01:34+00:00</updated><id>https://simonwillison.net/2008/Jun/27/peters/#atom-tag</id><summary type="html">
    
&lt;p&gt;&lt;strong&gt;&lt;a href="http://peter.michaux.ca/article/8069"&gt;Module Pattern Provides No Privacy... at least not in JavaScript(TM)&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;
JavaScript variables hidden inside a closure aren’t as hidden as I thought—it turns out you can pass a closure as the second argument to eval (at least in Firefox) and “steal” private variables back out of it.

    &lt;p&gt;&lt;small&gt;&lt;/small&gt;Via &lt;a href="http://ajaxian.com/archives/evalfooa-objfn-how-you-arent-private-in-firefox"&gt;Ajaxian&lt;/a&gt;&lt;/small&gt;&lt;/p&gt;


    &lt;p&gt;Tags: &lt;a href="https://simonwillison.net/tags/closures"&gt;closures&lt;/a&gt;, &lt;a href="https://simonwillison.net/tags/firefox"&gt;firefox&lt;/a&gt;, &lt;a href="https://simonwillison.net/tags/javascript"&gt;javascript&lt;/a&gt;, &lt;a href="https://simonwillison.net/tags/modulepattern"&gt;modulepattern&lt;/a&gt;, &lt;a href="https://simonwillison.net/tags/pete-michaux"&gt;pete-michaux&lt;/a&gt;&lt;/p&gt;



</summary><category term="closures"/><category term="firefox"/><category term="javascript"/><category term="modulepattern"/><category term="pete-michaux"/></entry></feed>