Fustercluck

Pseudo-epistemological study of blogging in an existentialistic context, expresed in a Nietzsche-esque-ish mood and shit like that.... oh, and something about bacon and javascript.

Feb 17

Javascript Shrunk Part 1

3 Ways of building the same javascript counter

The two “slowest”

  var a = function() {

if (!arguments.callee.i) arguments.callee.i = 0;

return ++arguments.callee.i;

}

  var b = function() {

return arguments.callee.i ? ++arguments.callee.i: arguments.callee.i = 0;

}

The two “fastest”

  var c = function() {

return this.i ? ++this.i: this.i = 0;

}

  var d = function() {

return this.i = ++this.i || 0;

}

Example Output:

  a() // => 1

a() // => 2

a() // => 3

...

b() // => 1

b() // => 2

b() // => 3

etc...

  • Safari:
  • Firefox:
  • IE6:

Page 1 of 1