|
Unix Programming - Applying Minilanguages - Case Study: JavaScript
Case Study: JavaScript
JavaScript is an open-source language designed to be embedded in
C programs. Though
it is also embedded in web servers, its original and best-known
manifestation is client-side JavaScript, which allows you to embed
executable code in Web pages to be run by any JavaScript-capable
browser. That is the version we will survey here.
JavaScript is a fully Turing-complete interpreted language with
integers, real numbers, booleans, strings, and lightweight
dictionary-based objects resembling those of
Python.
Values are typed, but variables can hold any type; conversions between
types are automatic in many contexts. Syntactically JavaScript resembles
Java with some
influence from Perl, and features Perl-like regular
expressions.
Despite all these features, client-side JavaScript is not quite a
general-purpose language. Its capabilities are severely restricted
to prevent attacks on the browser user through Web pages
containing JavaScript code. It can accept input from the user and
generate or modify Web pages, but it cannot directly alter the
contents of disk files and cannot open its own network
connections.
Over time, the JavaScript language has become more general and
less bound to its client-side environment. This is something that can
be expected to happen to any successful specialized language as its
possibilities unfold in the minds of developers and users. Client
JavaScript now interacts with its environment by reading and writing
values in a single special object called the browser DOM (Document
Object Model). The language still has some legacy APIs to the browser
that don't go through the DOM, but these are deprecated, not present
in the ECMA-262 standard for JavaScript, and may not be supported in
future versions.
The standard reference for JavaScript is JavaScript:
The Definitive Guide [FlanaganJavaScript]. Source code
is downloadable.[94]
JavaScript makes an interesting study for two reasons. First, it's
about as close to being a general-purpose language as one can get
without actually being there. Second, the binding between client-side
JavaScript and its browser environment via a single DOM object is well
designed, and could serve as a model for other embedding
situations.
[an error occurred while processing this directive]
|