There are a few typos here, and can potentially return nothing.  How about something more like this?
```
if (obj.__repr__ !== undefined)
  return obj.__repr__();
else if (obj.__class__ !== undefined && obj.__class__.__module__ !== undefined && obj.__class__.__name__ !== undefined)
  return '<' + obj.__class__.__module__ + '.' + obj.__class__.__name__ + ' object>';
return obj.toString();
```