Javascript:: The Good Parts
Javascript:: The Good Parts
Javascript:: The Good Parts
alert(digit_name(3)); // 'three'
Slow
var digit_name = function (n) {
var names = ['zero', 'one', 'two',
'three', 'four', 'five', 'six',
'seven', 'eight', 'nine'];
return names[n];
};
alert(digit_name(3)); // 'three'
Closure
var digit_name = (function () {
var names = ['zero', 'one', 'two',
'three', 'four', 'five', 'six',
'seven', 'eight', 'nine'];
Beautiful Code
JSLint
• JSLint defines a professional subset of
JavaScript.
• It imposes a programming discipline that
makes me much more confident in a dynamic,
loosely-typed environment.
• http://www.JSLint.com/
WARNING!
JSLint will hurt your
feelings.
Unlearning Is
Really Hard
Josh Billings
The Very Best Part:
Stability
No new design errors
since 1999!
Coming Soon
• [ES3.1] ECMAScript Fifth Edition
• Corrections
• Reality
• Support for object hardening
• Strict mode for reliability
"use strict";
• Waiting on implementations
Safe Subsets
• The most effective way to make this language
better is to make it smaller.
• FBJS
• Caja & Cajita
• Web Sandbox
• ADsafe
• The next edition of ECMAScript might
include a secure formal subset.
The Good Parts
• Your JavaScript application can reach a
potential audience of billions.
• If you avoid the bad parts, JavaScript works
really well. There is some brilliance in it.
• It is possible to write good programs with
JavaScript.