title: Google Sheets script - "Cannot read property of undefined" (when it's not)
body: <p>I am trying to de-construct a <a href="https://developers.google.com/adwords/scripts/docs/solutions/account-summary" rel="nofollow">Google-Team's script</a> for getting a report from AdWords and writing it into Google Sheets spreadsheet. I am testing it in Apps editor and getting the "Cannot read of undefined..." error. </p>
  
  <p>I currently have two .gs files in my project:</p>
  
  <p><strong>1. Function definition ("class"), <code>empty_row.gs</code> file:</strong></p>
  
  <pre><code>function SpreadsheetAccess(spreadsheetUrl, sheetName) {
  this.spreadsheet = SpreadsheetApp.openByUrl(spreadsheetUrl);
  this.sheet = spreadsheet.getSheetByName(sheetName);
  
  this.findEmptyRow = function(minRow, column) {
      var values = this.sheet.getRange(minRow, column, this.sheet.getMaxRows(), 1).getValues();
  
      for (var i = 0; i &lt; values.length; i++) {
          if(!values[i][0]) {
              return i + minRow;
          }
      }
      return -1;
      };
  
  this.addRows = function(howMany){
      this.sheet.insertRowsAfter(this.sheet.getMaxRows(), howMany);
  };
  
  this.writeRows = function(){
      this.sheet.getRange(startRow, startColumn, rows.length, rows[0].length).setValue(rows);
  };
  }
  </code></pre>
  
  <p><strong>2. and a <code>main.gs</code>file where I instantiate the object:</strong></p>
  
  <pre><code>var spreadsheetUrl = 'https://docs.google.com/spreadsheets/d/someurl/edit#gid=1540200210';
  var sheetName = 'baba';
  
  function main() {
    var object = SpreadsheetAccess(spreadsheetUrl, sheetName);
    var emptyRow = object.findEmptyRow(1, 1);
  
    Logger.log("The empty row is: %s", emptyRow);  
  }
  </code></pre>
  
  <p>When I run <code>main{}</code> I am getting this:</p>
  
  <blockquote>
    <p>TypeError: Cannot call method "findEmptyRow" of undefined. (line 6, file "main")</p>
  </blockquote>
  
  <p>Why is my object undefined? I have defined:</p>
  
  <ul>
  <li>the spreadsheetUrl</li>
  <li>sheetName</li>
  <li>I have passed these to my function call </li>
  <li>and finally the function is defined in the same project, separate file</li>
  </ul>
  
  <p>What gives? thanks!</p>