I've got a simple Google Apps Script code like this:
function throwsError(){
  var inboxThreads = GmailApp.getInboxThreads();
  var sliceArr = inboxThreads.slice(0, 3);
  Logger.log(sliceArr.length);
  for each (var thread in sliceArr){
    Logger.log(inboxThreads.containsThread(thread));
  }
}
function doesNotThrowError(){
  var inboxThreads = GmailApp.getInboxThreads();
  var sliceArr = inboxThreads.slice(0, 3);
  Logger.log(sliceArr.length);
  for (var i = 0; i < sliceArr.length; i++){
    Logger.log(inboxThreads.containsThread(sliceArr[i]));
  }
}
Array.prototype.containsThread = function(thread){
  Logger.log("Here");
  Logger.log(thread);
  return this.filter(function(t){ return t.getId() == thread.getId(); }).length > 0;
}
As the function names indicate, throwsError() throws an error of TypeError: Cannot find function getId in object function (thread) {...}.. doesNotThrowError() runs perfectly without issue. The only difference between them is that one uses a for loop and the other uses a for each loop.
The log output of throwsError() is as follows:

It seems that there are only 3 items in my sliceArr array, but the containsThread is being called 4 times. (Additionally, the 4th time it seems that it is passing in the containsThread function into itself as the parameter). Any ideas what could be causing this?
My inclination is that this is a bug with Google Apps Script, but I wanted to check here in case anyone else had some insight. Note that Google Apps Script works on JS 1.6 with some portions of 1.7 and 1.8
 
    