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 Fourth Edition
• Corrections
• Reality
• Support for object hardening
• Strict mode for reliability
• Waiting on implementations
Not Coming Soon
• [ES4] This project has been
cancelled.
• Instead, [ES-Harmony].
• So far, this project has no defined
goals or rules.
Safe Subsets
• The most effective way to make this
language better is to make it smaller.
• FBJS
• Caja & Cajita
• ADsafe
• These subsets will be informing the
design of a new secure language to
replace JavaScript.
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.