The Truth about JavaScript

Brendan Eich

Mozilla Corporation

The Truth Hurts (It Blinds)

Tell all the Truth but tell it slant
Success in Circuit lies
Too bright for our infirm Delight
The Truth's superb surprise

The Big Picture

JavaScript 2 Update

New Since Last Year

Program Units


ByteArrays, Vectors, Tuples

  • ByteArray class, converts from Array
    • etc. work on it, albeit generically
  • Parameterized type Vector.<T>
    • Dense, optionally fixed length
    • Vector.<T>(length : uint = 0, fixed : boolean = false)
  • ByteArray could be subsumed by Vector.<byte>
    • If we are willing to add a byte type
  • Structural array type A = [int, string, boolean] is a tuple
    • Not a named Tuple type!
    • Fixed length with type constraints
    • Type-checked compatibility with Array

Type System Trade-offs

  • We believe untyped objects will abound forever
  • But typed APIs, including structural types, will emerge
  • Nominal (class) hierarchies (DOM, Flex, etc.) likely too
    • But they won't take over the Web
    • So we're not turning JS into Java
  • Most common case: Untyped code calling Typed API
  • Another important case: class matching structural type

Structural Types as Contracts

  • Given function f(a : {p: int, q: string}) ...
    • Assume it's a structurally typed API method
  • What does f({p: 42, q: "hi"}) check, and when?
  • Use cases want early and deep checking
    • An untyped object could mutate after the check
    • Checking every read too costly, yet still incomplete
    • See MochiKit's isArrayLike, isDateLike
  • Given a class C with the right instance vars,
    • passing f(new C(42, "hi")) can go fast

Performance Trends

  • "Fastest browser on the planet" i-bench bragging
  • Pure JS performance not critical (yet, for common cases)
  • DOM and rendering dominate critical paths, but:
    • DOM bindings hide JS dynamic typing costs
    • Developers are pushing hard at the frontiers
  • John Resig wrote and collected some benchmarks

New Projects



  • Inspiration:
  • Map IronPython and IronRuby to Tamarin
    • Avoid forking C# source using Mono C# compiler
    • Bytecode translation a la IKVM, JaCIL
  • Led by Seo Sanxiyn of FePy and PyPy fame


  • Goal: support Tamarin in other browsers
  • Led by Mark Hammond of Windows Python fame
  • First target: IE integration as an ActiveScript engine
  • Handle these RFC 4329 content <script> type= values:
    • application/ecmascript;version=4
    • application/javascript;version=2
  • Other browser integrations to follow

The Truth About JavaScript

  • JavaScript is...
  • Occasionally a curse
  • Often a blessing, formerly in disguise
  • Spreading from the browser (Rhino on Rails)
  • Growing muscle and speed
  • Upgradeable in browsers (even in IE)
  • The 'J' in AJAX The 'j' in Ajax?

Vlad's Photos Demo