imathis/octopress — Issue #389: Javascript exception in twitter.js
Author: scottwb
Created: 2012-01-22 01:55:36+00:00
State: open

_Sorry I can't fork and pull-request this because my real fork is private right now._

I ran into an exception today in twitter.js. I have no idea why this wasn't happening before...it may be due some additional javascript I added elsewhere in the site today. The problem is in the way it is enumerating an array. The `for` loop in this code is the culprit:

```javascript
function showTwitterFeed(tweets, twitter_user) {
var timeline = document.getElementById('tweets'),
content = '';
for (var t in tweets) {
// ...truncated...
```

When there are 4 things in the `tweets` array, it enumerates `t` through the values `1`, `2`, `3`, `4`, `copy` (a function), and crashes trying to reference the `text` member of the `copy` function. My guess is the third-party javascript I added today may be extending `Array.prototype` with a `copy` function.

The solution is to change the for loop to use `length` like so:

```javascript
function showTwitterFeed(tweets, twitter_user) {
var timeline = document.getElementById('tweets'),
content = '';
for (var t=0, len=tweets.length; t