[wp-hackers] Prototype.js and Amazon Link-Enhancer Conflict

Sam Angove sam at rephrase.net
Sat Dec 16 15:50:56 GMT 2006


On 12/17/06, Mike Koepke <mkoepke1 at mikekoepke.com> wrote:
>
> We have both isolated the issue to the inclusion of the Amazon script
> along side of prototype.js.   As WP 2.1 will be including prototype.js,
> I thought I'd point out the potential problem to others in the future
> and see if someone has a fix for the conflicts.

It might have something to do with the `for in` loops in the link
enhancer JavaScript, e.g. `for (var locale in imp)` on line 207.

Basically, it's not safe to use `for in` to loop over arrays without
extra type checking, because any third-party JavaScript can wreak
havoc by extending the object prototype. That looks like what's
happening here. There was quite a bit of drama last year over
Prototype.js breaking people's scripts:

   http://erik.eae.net/archives/2005/06/06/22.13.54/
   http://blog.metawrap.com/blog/WhyIDontUseThePrototypejsJavaScriptLibrary.aspx

If that is the problem, the Amazon code has to be changed. There's a
succinct explanation (and explanation of the fix) here:

  http://yuiblog.com/blog/2006/09/26/for-in-intrigue/


More information about the wp-hackers mailing list