Sneaky Abstractions

Subscribe to my Feed, follow me on , recommend me on Working With Rails or see my code on GitHub

routes.js update

Posted on July 04, 2007 11:18 Tagged with routes, javascript.

I’ve made a few changes to the JavascriptRoutes plugin to make it Even Betterâ„¢. One of those changes is to check hasOwnProperty on parameters and options, and it has made it clear to me how important it is to not mess around with Object.prototype (or, make sure an object’s properties don’t come from somewhere in the prototype chain).

Before:

Object.prototype.iThinkEveryObjectShouldHaveThis = 'for sure';
Routes.generate({controller:'lolcats', action:'show', id:1}, {onlyPath:true})
// => "/lolcats/1?iThinkEveryObjectShouldHaveThis=for%20sure"

Now:

Object.prototype.iThinkEveryObjectShouldHaveThis = 'for sure';
Routes.generate({controller:'lolcats', action:'show', id:1}, {onlyPath:true})
// => "/lolcats/1"

This also means the plugin won’t work in browsers that don’t have the hasOwnProperty method. Those that I know of that don’t have this are Safari 1.3 and IE 5.0. It also uses try-catch, which was only introduced in JavaScript 1.5. If enough people complain, I might try to change this.

If the radiance of a thousand suns were to burst at once into the sky, that would be like the splendor of the mighty one. Now I am become Death, the destroyer of worlds.