not a JS1K winner
not your definitive guide
to writing good javascript
you may experience javascript
in a different light
you may start getting
OCD tendencies
you may write less readable code
<body> <canvas id="c"></canvas> <script> var b = document.body; var c = document.getElementsByTagName('canvas')[0]; var a = c.getContext('2d'); document.body.clientWidth; // fix bug in webkit: http://qfox.nl/weblog/218 // start of submission // SCRIPT // end of submission // </script> </body>
var j=0; var k=0; // before
var j=0, k=0; // after
var j=k=0; // better
j=k=0; // best
function (a, b, c, d) { c = a + b; //.. }
while (true); // usual
while (1); // better
for (;;); // best
for (i=0;i<number;i++) // usual
for (i=number;i--;) // best
for (i=0;i<number;i++);
for (i=0;i<number/2;i++);
for (i=0;i<number;i++) {
if (i%2) {}
}
function(){}
012345678901
x=function(a,b,c,d,e){
y=function(a,b,c,d,e){
becomes xF,yF where F = function(a,b,c,d,e)
setInterval(function(a,b,c,d,e){ // blabla });
a=b;if(a){} // before
if(a=b){} // after
if (a==null) {} // before
if (!a){} // after
if (a) doSomething() // usual
a && doSomething() // after
if (!a) doSomething()
a || doSomething()
["apple", "banana", "orange", "pineapples"] // before
"apple0banana0orange0pineapples.split(0) // after
'zzzzzzzzzzzzzzzzzzzzzzzzzzzzzz' // before
for(a="",i=30;i--;)a+='z' // after
a=Array(30).join('z') // better
d = document.createElement('canvas') // before
d = a.cloneNode(); // after
a.width = window.innerWidth // before
a.width = innerWidth // after
for(i in a)(function(i){a[i[0]+(i[6]||'')]=(''+a[i])[27]?a[i]:function(_){a[i]=_}})(i)
a.globalComposite='destination-over' // before
a.gC('destination-over') // after
c.strokeColor = 'white' // before
c.strokeColor = '#fff' // after
Math.floor(x) // before
x = ~~x // after
million=1000000 // before
million=1e6 // after
Math.round(a) // before
a+.5|0 // after
java -jar compiler/compiler.jar --externs externs.js --compilation_level ADVANCED_OPTIMIZATIONS --js source.js --js_output_file output.js
var a,b,c,d,e; a=10,b=....
a=10,b=....
bla;bla;bla; // before
bla;bla;bla // after
0.5 // before
.5 // after
var a = 7, b = 7, c = 7;
ctx.arc(x, y, r, 0, 2 * Math.PI); // before
ctx.arc(x, y, r, 0, 7); // after
#1 Strange crystals II by Philippe Deschaseaux @ehouais
#2 Furbee, get out of that tunnel ASAP by Roman Cortes @romancortes
#3 3013 The 䕵 space-time fracture by Mathieu 'p01' Henri @p01
#4 Synth Sphere by Noah Weninger@gleurop
#5 Pointillism by Benjamin Bill Planche @b_aldream
#6 3D City Tour by Jani Ylikangas
#7 Comanche by Siorki @Siorki
#8 Color Factors by Pablo Caro @hugoware
#9 Winter Wrap Up by Arne @veubeke
#10 Psychedelic animation by Piotr Stosur
from https://gist.github.com/zz85/5522800
"IMHO best compression scheme: imagination+time+math skills."
https://twitter.com/ehouais/status/313943128962908160