prototypejs / prototype

Prototype JavaScript framework
http://prototypejs.org/
Other
3.54k stars 639 forks source link

Ajax.Request broken in minified 1.7.2 #312

Closed g-schanner closed 7 years ago

g-schanner commented 8 years ago

It seems that a regular Ajax.Request call breaks in the minified version of the library. See not minified: https://jsfiddle.net/4db2rbdy/1/ versus minified: https://jsfiddle.net/wp1zupwa/1/

I also tested several online minifying websits (such as https://javascript-minifier.com/ and http://refresh-sf.com/) but to no avail.

However, the Google Closure compiler seems to work fine https://closure-compiler.appspot.com/home.

Tested it with Firefox 45.0.1 and Chrome 39.0.2171.95 (64-bit)

(Probably somehow related to https://github.com/cdnjs/cdnjs/issues/2872)

jwestbrook commented 8 years ago

The Class construct that builds out Prototype's pseudo OOP structure examines the name of the first parameter in each class method, in your example the initialize method. If the parameter name is $super then that variable is set to the parent/super class instance's method of the same name. In the examples you gave the parameter is renamed to e instead. Google's Closure Compiler on SIMPLE compression does not rename that parameter (I use Google's minified version on my production site).

I think if the $super variable can be protected from being renamed then the minification would work successfully.

I wrote a StackOverflow answer that has a simple Class definition that illustrates the inheritance and the use of $super http://stackoverflow.com/a/15527223/341491