4 ms·
Why this? // Shorten some names. var math = Math;
by ttty 13y ago
Why this?
// Shorten some names.
var math = Math;
- minikomi 13y agoBecause when it's run through the Google closure compiler it becomes E=Math,F=E.sqrt,G=E.max
- choult 13y agoCapital letters are bigger, and therefore take up more space.
- stickupkid 13y agoNo.
- rejschaap 13y agoThat is before minifying. The variable name "math" was chosen for readibility in the non-minified version. The variable math can be renamed during the minifying process to a short identifier, in this case "E". Since the Math object is used quite a lot, it is worth the assignment to rename it.
- deleted 13y ago[deleted]
- ggambetta 13y agoFor minification, as someone else said. I originally wrote this for a JS1K competition some years ago, so it's not geared towards readability, but towards small code size. I had a really, really ugly trick that saved me a couple of bytes which I removed before posting to HN. I figured out I was using canvas.getImageData() and canvas.putImageData(). So I did this: var tID = "tImageDatA"; canvas["ge"+tID](); canvas["pu"+tID"](); You can see that in the original source: http://gabrielgambetta.com/tiny_raytracer_full.js http://gabrielgambetta.com/tiny_raytracer_full.js Not my proudest hack :D
- merkitt 13y agoI just looked at this childhood drawing of yours: http://www.gabrielgambetta.com/img/1986-listado.jpg http://www.gabrielgambetta.com/img/1986-listado.jpg Is that BASIC CODE mixed in with bugs bunny??! Raytracer or no raytracer, this is exceedingly cool.
- ggambetta 13y agoYes, that is (my 5 year old idea of) ZX Spectrum Basic. It follows the format of the listings published in Microhobby (http://microhobby.speccy.cz/mhf/031/MH031_08.jpg http://microhobby.speccy.cz/mhf/031/MH031_08.jpg - in particular, look at the "NOTAS GRAFICAS" sidebar). I grew up with that :) My programming has improved, my drawing abilities not so much.
- davidpardo 13y agoI remember typing that listing, almost thirty years ago. I owe a lot of what my life is now to Microhobby.
- jbochi 13y agoClosure compiler will rename the math variable.