#108 ✓resolved

prototype.js won't load due it clobbering "Element"

Reported by nickg | March 15th, 2010 @ 10:16 AM

prototype.js has the following gem:

(function() {                                                                                                                                  
var element = this.Element;
this.Element = function(tagName, attributes) {

attributes = attributes || { };
tagName = tagName.toLowerCase();                                                                                                             
var cache = Element.cache;                                                                                                                   
if (Prototype.Browser.IE && attributes.name) {                                                                                               
  tagName = '<' + tagName + ' name="' + attributes.name + '">';                                                                              
  delete attributes.name;                                                                                                                    
  return Element.writeAttribute(document.createElement(tagName), attributes);                                                                
if (!cache[tagName]) cache[tagName] = Element.extend(document.createElement(tagName));                                                       
return Element.writeAttribute(cache[tagName].cloneNode(false), attributes);

Object.extend(this.Element, element || { });
if (element) this.Element.prototype = element.prototype;

This effectively wipes out envjs's Element. Here's the trace

nickg-macbook:env-js nickg$ ./tester.sh  
Rhino 1.7 release 2 2009 03 22
js> load("client9-env-js/dist/env.rhino.js");
[  Envjs/1.6 (Rhino; U; Mac OS X x86_64 10.6.2; en-US; rv:1.7.0.rc2) Resig/20070309 PilotFish/  ]
js> load('/Users/nickg/Downloads/scriptaculous-js-1.8.2/lib/prototype.js');
js: "/Users/nickg/Downloads/scriptaculous-js-1.8.2/lib/prototype.js", line 1561: uncaught JavaScript runtime exception: TypeError: Cannot find function toLowerCase in object [object HTMLDocument].
    at /Users/nickg/Downloads/scriptaculous-js-1.8.2/lib/prototype.js:1561
    at client9-env-js/dist/env.rhino.js:6302
    at client9-env-js/dist/env.rhino.js:7079
    at client9-env-js/dist/env.rhino.js:5555
    at /Users/nickg/Downloads/scriptaculous-js-1.8.2/lib/prototype.js:2465

By renaming envjs's Element to _Element it was able to load correctly. But that's ghetto.

Namespaces? Modules?

Comments and changes to this ticket

Please Sign in or create a free account to add a new ticket.

With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.

New-ticket Create new ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile ยป

a javascript browser environment

People watching this ticket