views:

41

answers:

1

In an attempt to save space, I made a whole bunch of aliases for functions in my code. It works fine in FF, but now I'm trying to add support for IE and it's not happy.

j=String;
f0=j.fromCharCode;
j=j.prototype;
j.f1=j.indexOf;
j.f2=j.lastIndexOf;
j.f3=j.concat;
j.f4=j.substring;

function alias(c,e){return function(){return c[e].apply(c,arguments);};}

w=window.location;
d=document;
b=document.body;
f5=alias(d,"createElement");
f6=alias(b,"appendChild");
f7=alias(d,"getElementById");
...etc

I know for sure the alias() function doesn't work in IE. Is there an alternative way that works in both browsers?

+2  A: 

This is one of those answers that doesn't directly answer your question, but I think it will help:

You should write your code without all the short variables and aliases. Write it out full form as it will be much easier to maintain.

Then, when you move the code to production, put your code through a minifier that does the aliasing and variable shortening for you.

You could try out either of these two to do it for you (There are lots of other good ones as well):

  1. Google Closure Compiler
  2. Dean Edwards Packer (Turn on 'Shrink variables')
Doug Neiner
Totally agree. Writing unreadable code is like shooting yourself in the foot. Let some automated tool make it unreadable (compressed) for you.
Miguel Ventura
Thanks I'm aware. In this case the packer is out of the question (cannot use those symbols) so I had to shorten it by hand. Code is already finished, just getting errors due to the aliases in IE.@Miguel This is not the type of code I'll ever edit or maintain, it's purpose is to be short and fast only.
graw
@unknown I am not trying to leave you stranded, but I don't have IE on my machine. I attempted a bunch of changes long distance via browserlab (and crazy `innerHTML = resultOftext`) to no avail. Sorry I can't be more help.
Doug Neiner
@Doug I couldn't find anything either don't worry, just thought it worth asking here. I will use wrapper functions if no other solution presents itself. Cheers
graw