title: Why does a closured function not protect the values of an object but a naked function will?
body: <p>Why does a closured function not protect the values of an object but a naked function will?
  <a href="http://jsfiddle.net/u8cuk/7/" rel="nofollow">I have the below code on jsFiddle</a>.</p>
  
  <p>I'm using Lo-Dash <code>_.assign</code> function with a default <code>Object</code>. Like so:</p>
  
  <pre><code>var cnst = _.constant({test: 'It Works!'})
  var newCnst = _.assign(cnst(), {test: "It doesn't work!"})
  console.log(cnst())
  console.log(newCnst)
  </code></pre>
  
  <p>Which results in:</p>
  
  <pre><code>{test: "It doesn't work!"}
  {test: "It doesn't work!"}
  </code></pre>
  
  <p>So I just do a naked constant function like so:</p>
  
  <pre><code>var test = function(){return {test: 'It Works!'}}
  var newTest = _.assign(test(), {test: "It doesn't work!"})
  console.log(test())
  console.log(newTest)
  </code></pre>
  
  <p>Which results in:</p>
  
  <pre><code>{test: 'It Works!'}
  {test: "It doesn't work!"}
  </code></pre>
  
  <p>Just like it should. Why is the closured constant value not protected? Even when I do it myself:</p>
  
  <pre><code>var constant = function(value){return function(){return value}}
  var t = constant({test: 'Closured Works!'})
  var t2 = _.assign(t(), {test: "No closured doesn't work!"})
  console.log(t())
  console.log(t2)
  </code></pre>
  
  <p>Which results in:</p>
  
  <pre><code>{test: "No closured doesn't work!"}
  {test: "No closured doesn't work!"}
  </code></pre>