title: When object is passed to an exports function, script fails. When same object is passed directly to function, it passes
body: <p>I have a function which creates objects from scraped website data. The objects look like this:</p>
  
  <pre><code>{ 
    name: 'Object Name',
    baseURL: 'http://xyz123.com',
    mainImg_select: '#item_image a',
    mainImg_ref: 'href',
    moreImg_select: '.extra_images',
    moreImg_ref: 'href',
    one_brand: '',
    urls: [],
    categories:
     [ { name: 'Cat 1',
         url: 'http://xyz123.com/category1' },
       { name: 'Cat 2',
         url: 'http://xyz123.com/category2' },
       { name: 'Cat 3',
         url: 'http://xyz123.com/category3' }
     ] 
  }
  </code></pre>
  
  <p>I'm running it through some functions that use the <code>request</code> and <code>cheerio</code> modules. The <code>request</code> function is, somehow, deleting my objects' <code>categories</code> property; when logging the object I see <code>"categories: undefined"</code> (so the property is still there, just its contents are removed.</p>
  
  <p>What's REALLY bizarre is that this ONLY happens when I'm using an object stored in a variable that is created by my script. If I create the object, log it, then copy and paste it directly into the code (like above except <code>var object123 = {stuff goes here}</code>) then my Node script works just fine.</p>
  
  <p><code>PrepJSON</code> is a class which takes a JSON file turns it into an object. To avoid this becoming a massive wall of code, I've pastebin'd it here: <a href="http://pastebin.com/Tgx0nnmR" rel="nofollow">http://pastebin.com/Tgx0nnmR</a></p>
  
  <p><a href="http://pastebin.ca/2404668" rel="nofollow">This doesn’t work</a></p>
  
  <p><a href="http://pastebin.ca/2404667" rel="nofollow">This works</a></p>
  
  <p>The only difference is that in one I'm using a returned object from my <code>prepJSON</code> function, in the other I'm console.logging that object, running the function, copying the log, putting it in a variable - then magically the script works.</p>
  
  <p>The rest of the object is NOT touched by the script - only the categories, which stores an array of objects. For completeness, here's how the <code>object.categories</code> are created in prepJSON. This is the only time a script touches them:</p>
  
  <pre><code>storeCats.categories = (function(){
          $('.view-Departments .field-content a').each(function(index){
          storeCats.categories.push({'name': $(this).text(), 'url': $(this).attr('href')}); 
          if(index == $('.view-Departments .field-content a').length -1) {callback(null);} 
      })}
  )();
  </code></pre>