experimenting with a more general way of hashing a namespace, for future javascript golf. the idea is that existing browser objects can be hashed so that wasteful strings like createDocumentFragment
can be avoided entirely, and keys from several objects (such as document
, window
, String
, etc.) can be hashed into one namespace.
for example:
d = document
d.body.appendChild(d.createElement("script")).src="URL"
could be shortened to
d = document
d[rk][XU](d[Ou]("script")).src="URL"
this specific approach takes every key on the document, turns it into a large number by multiplying each codepoint with an index and then summing and modding by 3456 (54 * 64), which is the maximum number of items representable with a two-byte javascript identifier:
/[a-z_$][0-9a-z_$]/i
this yields decent results. in an empty chrome page, there were only 3 collisions. the idea is that the upper bound can be lowered as necessary, until the collisions are acceptable.
okay, so a big flaw in this approach is that in a significantly saturated namespace, there are bound to be keywords that overlap with existing javascript keywords like
do
andin
. blarg.