I say.

A blog by Joakim Beijar, I solve interesting and mundane problems at Mios Ltd and hack at night on github.com/kaa.

...on mysterious redirects with MooTools

21 Nov 2008

While developing some javascript classes with MooTools’ new Class() pattern I found myself being mysteriously redirected from http://www.example.com/test.html to http://www.example.com/[object Object] every time I opened the page.

Turns out instead of saying

  var C = new Class({...});
  var c = new C();

I had, forgotten the second new and written

  var C = new Class({...});
  var c = C();

I can’t explain the redirect, but once I added the missing new keyword everything was back to normal. This happened in a much more convoluted situation which made the missing keyword harder to spot. I guess it goes to show that you shouldn’t try to be clever, even when “just writing an unit test”.