Download JavaScript

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts

URL redirection wikipedia , lookup

Transcript
Compendium Klaus Schneider
E-Business
JavaScript
The following compendium will show the history, the features, the use in the web and versions of
JavaScript. Firstly, the definition of JavaScript will be given.
Definition
JavaScript is an implementation of the ECMAScript language standard and is typically used to enable
programmatic access to computational objects within a host environment. It can be characterized as a
prototype-based object-oriented1 scripting language that is dynamic, weakly typed and has first-class
functions. It is also considered a functional programming language2 like Scheme and O’Caml because
it has closures and supports higher-order functions.3
JavaScript is primarily used in the form of client-side JavaScript, implemented as part of a web
browser in order to provide enhanced user interfaces and dynamic websites. However, its use in other
applications is not insignificant.
JavaScript was influenced by several languages; in particular, it was designed to look like Java, but be
easier for non-professional programmers to work with.4
JavaScript is a trademark of Sun Microsystems. It was used under license for technology invented and
implemented by Netscape Communications and current entities such as the Mozilla Foundation. 5
History
Brendan Eich of Netscape originally developed JavaScript, but in the beginning it was called Mocha.
Later, the name was changed into LiveScript and finally to JavaScript. JavaScript was first introduced
and deployed in the Netscape browser version 2.0B3 in December 1995. 6
JavaScript, apart of the name, is not related to the Java programming language, but they have some
similarities. Both languages are influenced by the C-syntax and moreover JavaScript copies many
Java names and naming conventions. The name of the language is the result of a marketing
agreement between Netscape and Sun. The main design in JavaScript is taken from the Self and
Scheme programming languages.7
Through the years, JavaScript has become one of the most popular programming languages in the
web.
Features
The upcoming features are common to all conforming ECMAScript implementations.
Imperative and structured
JavaScript supports all the structured programming syntax in C (e.g., if statements, while loops,
switch statements, etc.). One partial exception is scoping: C-style block-level scoping is not
supported (instead, JavaScript has function-level scoping). JavaScript 1.7, however, supports block-
1
http://www.ecma-international.org/publications/files/ECMA-ST/ECMA-262.pdf
http://www.blinkx.com/watch-video/douglas-crockford-on-functionaljavascript/xscZz8XhfuNQ_aaVuyUB2A
3 http://www.crockford.com/javascript/little.html
2
4
http://web.archive.org/web/20080208124612/http://wp.netscape.com/comprod/columns/techvision/inn
ovators_be.html
5 http://www.sun.com/suntrademarks/
6 http://en.wikipedia.org/wiki/JavaScript#cite_note-techvision-5
7 http://www.ecmascript.org/es4/spec/overview.pdf
Compendium Klaus Schneider
E-Business
level scoping with the let keyword. Like C, JavaScript makes a distinction between expressions and
statements. One syntactic difference from C is automatic semicolon insertion, in which the
semicolons that terminate statements can be omitted.8
Dynamic
Dynamic typing
As in most scripting languages, types are associated with values, not variables. For example, a
variable x could be bound to a number, later rebound to a string. JavaScript supports various ways
to test the type of an object, including duck typing.9
Object based
JavaScript is almost entirely object-based. JavaScript objects are associative arrays, augmented
with prototypes (see below). Object property names are string keys: obj.x = 10 and obj["x"] = 10 are
equivalent, the dot notation being syntactic sugar. Properties and their values can be added,
changed, or deleted at run-time. Most properties of an object (and those on its prototype inheritance
chain) can be enumerated using a for...in loop. JavaScript has a small number of built-in objects
such as Function and Date.10
Run-time evaluation
JavaScript includes a function that can execute statements provided as strings at run-time.11
Functional
First-class functions
Functions are first-class; they are objects themselves. As such, they have properties and can be
passed around and interacted with like any other object.12
Inner functions and closures
Inner functions (functions defined within other functions) are created each time the outer function is
invoked, and variables of the outer functions for that invocation continue to exist as long as the
inner functions still exist, even after that invocation is finished (e.g. if the inner function was
returned, it still has access to the outer function's variables) — this is the mechanism behind
closures within JavaScript.13
Prototype-based
Prototypes
JavaScript uses prototypes instead of classes for inheritance. It is possible to simulate many classbased features with prototypes in JavaScript. 14
Functions as object constructors
Functions double as object constructors along with their typical role. Prefixing a function call with
new creates a new object and calls that function with its local this keyword bound to that object for
that invocation. The constructor's prototype property determines the object used for the new
object's internal prototype. JavaScript's built-in constructors, such as Array, also have prototypes
that can be modified.15
Functions as methods
Unlike many object-oriented languages, there is no distinction between a function definition and a
method definition. Rather, the distinction occurs during function calling; a function can be called as a
8
Flanagan, David (2006). JavaScript: The definitive Guide. p.16. "Omitting semicolons is not a good
programming practice; you should get into the habit of inserting them."
9 http://en.wikipedia.org/wiki/JavaScript#cite_note-17
10 http://en.wikipedia.org/wiki/JavaScript#cite_note-17
11 http://en.wikipedia.org/wiki/JavaScript#cite_note-17
12 http://en.wikipedia.org/wiki/JavaScript#cite_note-17
13 http://en.wikipedia.org/wiki/JavaScript#cite_note-17
14 http://en.wikipedia.org/wiki/JavaScript#cite_note-17
15 http://en.wikipedia.org/wiki/JavaScript#cite_note-17
Compendium Klaus Schneider
E-Business
method. When a function is called as a method of an object, the function's local this keyword is
bound to that object for that invocation. 16
The use in the web
JavaScript is used for writing functions which are implemented in or included from HTML pages.
Furthermore is interacting with the Document Object Model (DOM) 17 of the page.
Some examples of this usage are:



Opening or popping up a new window with programmatic control over the size, position, and
attributes of the new window (e.g. whether the menus, toolbars, etc. are visible).
Validation of web form input values to make sure that they will be accepted before they are
submitted to the server.
Changing images as the mouse cursor moves over them: This effect is often used to draw the
user's attention to important links displayed as graphical elements.18
According to that, we can see that a web browser is by far the most common host environment for
JavaScript. Another common application of the engine is the web server.
Versions
Here is a list with the versions of JavaScript from the beginning until now:









16
IE 6-7 support JScript 5 (which is equivalent to ECMAScript 3, JavaScript 1.5)
IE 8 supports JScript 6 (which is equivalent to ECMAScript 3, JavaScript 1.5 - more bug fixes
over JScript 5)
Firefox 1.0 supports JavaScript 1.5 (ECMAScript 3 equivalent)
Firefox 1.5 supports JavaScript 1.6 (1.5 + Array Extras + E4X + misc.)
Firefox 2.0 supports JavaScript 1.7 (1.6 + Generator + Iterators + let + misc.)
Firefox 3.0 supports JavaScript 1.8 (1.7 + Generator Expressions + Expression Closures +
misc.)
The next version of Firefox will support JavaScript 1.9 (1.8 + To be determined)
Opera supports a language that is equivalent to ECMAScript 3 + Getters and Setters + misc.
Safari supports a language that is equivalent to ECMAScript 3 + Getters and Setters + misc.19
http://en.wikipedia.org/wiki/JavaScript#cite_note-17
Def.: The Document Object Model (DOM) is a cross-platform and language-independent convention
for representing and interacting with objects in HTML, XHTML and XML documents.
18
http://en.wikipedia.org/wiki/JavaScript#cite_note-17
19 http://ejohn.org/blog/versions-of-javascript/
17