|
|
JavaScript - Dynamic HTML |
JavaScript has been created by Netscape to embedd procedural programming
into HTML and build dynamic web pages. It is used also to enable scripting
in some applications of markup languages (PDF, photoshop, XUL, use JavaScript).
The syntax of the language is similar to that of Java or C.
JScript is a compatible version implemented by Microsoft in 1996, for Windows
only.
Elements of a web page are accessed as a hierarchy of objects, including
those of the Document Object Model (DOM,
a standard by the W3C): document, window, form, table, etc... No file output
is provided, for security.
The format described here is ECMAScript 1.5, the standard defined by the
ECMA group in 1999. More recent version exists, but not supported by all
browsers.
Features
- Object oriented, uses elements of the page as objects. Dynamic
objects.
- No file management nor input-output functions.
- Control of the browser.
- Events.
- Dynamic variables. Declared as var without type. JScript .NET adds
optional static type annotations.
- Dynamic and associative arrays.
- Primitive types (but undeclared) are: boolean, string, number, date, array.
- Build-in Date, Math, RegExp objects.
- A for..in construct allows to scan an array.
- Functions are declared with the function keyword, without return
type.
- Operators are those of Java plus strict ones: === and !==, for comparing
both values and types.
Syntax
Why to use it?
Building dynamic web pages, client-side processing. JavaScript is more
and more often used as a part of Ajax,
an asynchronous protocol for updating content of web pages with data taken
from the server. JavaScript
Frameworks are developped to build graphical interfaces for web applications.
It is used also to program XML-based graphical user interfaces.
See also
- E4X is an extension to ECMAScript 1.7 for an easier processing of XML documents. Used belong Ajax, it can make use of XML simpler, but for now not all browser implement the extension.
Websites and tools
- ECMAScript
The official 1999 definition of the language by ECMA. - JavaScript
The official project at Mozilla (formerly Netscape). - Directory
The Dmoz JavaScript directory offers a lots of tutorials, examples, and other resources. - Rhino
Standalone ECMAScript compiler to bytecode. - JSON
Tutorial for the simplest data exchange format, recognized by the JavaScript interpreter (1.5). - JavaScript tutorial. With exemples and case studies.
- JavaScript
in depth
Discussion of special features of JavaScript.
Sample code
|
Displaying a text
|
<script language ="JavaScript1.2">
var demo = "demo";
function dispstring(str)
{
for(i = 0; i < str.length; i++)
{
document.write(str.substring(i, i+1));
}
}
dispstring(demo);
</script>
|
