title: Node js module.exports get object
body: <p>I want to get the number calculated by this module, it returned an object.</p>
  
  <pre><code>module.exports = function calculate (s, key, k, d) {
    if (!k) k = 14
    if (!d) d = 3
    if (s.lookback.length &gt;= k + d * 2) {
      let stochK = []
      for (let j = 0; j &lt; d; j++) {
        let stochs = []
        for (let i = 0; i &lt; d; i++)
          stochs.push((function(x, length) {
            let low = [], high = []
            x.slice(0, length).forEach(function (period) {
              low.push(period.low)
              high.push(period.high)
            })
            return 100 * (x[0].close - Math.min(...low)) / (Math.max(...high) - Math.min(...low))
          })(s.lookback.slice(i+j), k))
        stochK.push(stochs.reduce((sum, cur) =&gt; { return sum + cur }, 0) / d)
      }
      let stochD = stochK.reduce((sum, cur) =&gt; { return sum + cur }, 0) / d
      s.period[key] = { K: stochK[0], D: stochD }
    }
  }
  </code></pre>
  
  <p>When I want to get the result of </p>
  
  <pre><code>K: stochK[0]
  </code></pre>
  
  <p>by calling</p>
  
  <pre><code>s.period.calculate.K
  </code></pre>
  
  <p>I got this error:</p>
  
  <pre><code>TypeError: Cannot read property "K" of undefined
  </code></pre>
  
  <p>What is the proper way of getting <code>K</code>?</p>
  
  <p>Part of the importing code:</p>
  
  <pre><code>var calculate = require('../../../lib/calculate')
  
  module.exports = {
  ...
    onPeriod: function (s, cb) {
      if (s.in_preroll) return cb()
      if (typeof s.period.calculate.K === 'number') {
      ...
        }
     }
  }
  </code></pre>