title: Javascript closure property manipulation
body: <p>There's a few threads on here that address this but none that gave a clear and concise answer to my problem.</p>
  
  <p>If I have a function such as the following;</p>
  
  <pre><code>function test(){
      var abc = "some value";
  
      return function concat(str) {
          return str + " " + abc;
      }
  }
  </code></pre>
  
  <p>such that i can concatenate a string with the "some value" string contained in the closure as follows</p>
  
  <pre><code>var myStr = test()
  console.log(myStr("this is"))
  </code></pre>
  
  <p>is there some way I can manipulate the abc variable at the point of defining myStr?</p>
  
  <p>I've been working with d3 quite a bit recently and building scales works as follows;</p>
  
  <pre><code>var myScale = d3.scale.linear()
      .domain(...)
      .range(...)
  </code></pre>
  
  <p>which I'm guessing works behind the scenes in a similar way to what I want to achieve.</p>
  
  <p>EDIT: This is what I wanted to achieve;</p>
  
  <pre><code>function test(){
      var abc = "some value";
  
      function concat(str) {
          return str + " " + abc;
      }
      concat.abc = function(value) {
          if (!arguments.length) { return abc;}
          abc = value;
          return concat;
      }
      return concat;
  }
  
  var myStr = test()
      .abc("another test")
  
  console.log(myStr("this is"))
  </code></pre>
  
  <p>Not sure I completely follow what's happening. </p>
  
  <p>Is concat.abc referencing the abc property within concat? Why are we returning concat from within the concat.abc property definition?</p>