Javascript
JavaScript is a Computer programming language of scripts mainly used for the interactive Web pages. It is a language directed objects with prototype, i.e. that the bases of the language and its principal interfaces are provided by objects which are not instanciés within classes but which each one are equipped with manufacturers making it possible to generate their properties, and in particular a property of prototyping which makes it possible to generate objects personalized heirs of them.
The language is created in 1995 by Brendan Eich, which took as a starting point many languages, in particular Java but by simplifying syntax for the beginners. The language currently with version 1.7 is an implementation of the standard ECMA-262. Version 1.8 is under development and will integrate elements of the Langage python. Version 2.0 of the language is designed to integrate the 4th version of standard ECMA.
History
JavaScript was created by Brendan Eich on behalf of the Netscape Communications Corporation. Javascript was called in the LiveScript beginning.
LiveScript and Mosaic Communications Corporation
Brendan Eich thus developed a language of script side waiter, called LiveScript, to reinforce the commercial offer of Web server of Mosaic Communications Corporation. The exit of LiveScript intervenes at the time where NCSA force Mosaic Communications Corporation to change name to become Netscape.Netscape then worked with the development of a directed version customer of LiveScript. A few days before its exit, Netscape changed the name of LiveScript for JavaScript. Sun and Netscape was partners, and the virtual machine increasingly popular Java. This name change served the interests of the two companies, and Sun promised not to continue Netscape.
Netscape and ECMAScript
In December 1995, Sun and Netscape announce (in) the exit of JavaScript. In March 1996, Netscape implements the engine Javascript in its navigator Web Netscape Navigator 2.0. The success of this navigator contributes to the fast adoption of Javascript in the development Web directed customer. Microsoft reacts then by developing JScript, which it then includes in Internet Explorer 3.0 in August 1996 for the exit of its navigator.Netscape then subjects JavaScript to ECMA for standardization. Work begins in November 1996, and finishes in June 1997 by the adoption of the new standard ECMAScript. The specifications are written in the document Standard ECMA-262 .
Concepts
JavaScript is described like a complement with Java in a common press release of Netscape and Sun Microsystems, dated from the December 4th 1995. This initiative contributed to create near the public a certain confusion between the two languages, close relations syntactically but at all in their fundamental concepts, and which perdure still today.The matter of Javascript is to handle in a simple way of the objects, with the data-processing directions, provided by a host application.
The ECMAScript standard
Javascript implements the specifications of the language ECMAScript, a standard written by ECMA in the document ECMA-262 .The third edition of ECMAScript, appeared in 1999 corresponds to version 1.5 of Javascript. Its implementation by Microsoft bears as for it the name of JScript . Adobe for its part, implements these specifications in its language ActionScript.
SpiderMonkey is the name of the implementation C of the JavaScript language used in Gecko, the engine of returned developed by Mozilla. SpiderMonkey is available under the license “ Tri-license  MPL/GPL/LGPL; ”.
Versions
The versions of the JavaScript language originate in the specifications of standard ECMA-262 defining ECMAScript. Javascript is a superset of ECMAScript, plus the functionalities suivantes :
1.5
Interpreter based on specifications ECMA-262 3rd edition.
1.6
All functionalities of version 1.5 more:- E4X
- Extension of the object Array
- Bringing together of the objects String and Array
1.7
All functionalities of version 1.6 more:- Generating (instruction yield)
- Itérateurs
- Definition of tables by comprehension (VAr evens = for (I in arranges (0, 21)) yew (i% 2 == 0);)
- Definition of local range (instruction let)
- Assignment déstructurante (Reference of multiple values: = maFonction ())
1.8
All functionalities of version 1.7 more:- Extension of Closings of expressions
- Extension of the generating Expressions
- Plus will extras for tables
2.0
Interpreter based on the specifications of the language ECMAScript Edition 4, a standard written by ECMA in document ECMA-262 4th edition.-
Implemented of the specifications ES4 in collaboration with Adobe: Project Tamarin.
Use
In a Web page
JavaScript code can be integrated directly within the Web pages, to be carried out there on the station customer. It is then the Navigateur Web which deals with the execution of these short periods of programs called scripts.
Generally, JavaScript is used to control the data seized in forms HTML, or to interact with document HTML via the interface DOM, provided by the navigator (one then speaks sometimes about dynamic HTML). It is also used to carry out dynamic, sometimes futile services or strictly cosmetics.
Another way ignored to use JavaScript is SVG and XUL and another dialect XML.
Incompatibilities
Netscape and Microsoft (with JScript in Internet Explorer) developed their own alternative of this language which each one supports the ECMAScript standard almost completely but has additional and incompatible functionalities, seldom used within the framework of the programming of Web pages. However JavaScript scripts are often the source of difficulties. Generally, they are due not to problems of Portabilité of the language, the various implementations respecting rather well the ECMAScript standard, but support of the various versions of the models of objects (DOM) provided by the navigators.
Vis-a-vis this problem one often uses a construction of the type:
It is however preferable to use a comparison on the type:
Or better still:
One checks thus that monObjet has well an implementation of method which one can then use. Generally, if a navigator does not manage the method of monObjet , it manages a comparable method methode2 , and one can then adapt the JavaScript code to the navigator who carries out it:
Another method consists in checking, with dimensions waiter, the navigator used by the customer and to send the corresponding code.
AJAX
Javascript is currently (November 2005) one of the essential components of the “ technologie ” AJAX (Asynchronous Javascript And XML). The majority of applications AJAX use the object XMLHTTPRequest (XHR) to send a request to a script waiter, and parser dynamically the results of this last via DOM. Internet Explorer is the first to propose this component, in the form of ActiveX, and this as of end of the year 90. They are only into 2002 that the developers massively start to use it, considering its adoption in FireFox. The versions of Internet Explorer former to the 7 did not manage the object XHR as described in the standards of the W3C but proposed equivalent a ActiveX control (starting from version 5), which imposes forks in the code, as shown above.
AJAX is one of technologies headlights of the movement Web 2.0 which defines the rich interfaces allowing the Net surfer a greater interactivity with the Web page.
JSON
JSON (Javascript Object Notation) is a format using the notation of the JavaScript objects to transmit structured information, in a similar, but more compact notation and nearer to the computer programming languages, than the XML.
In spite of the existence of the DOM, and the recent introduction of E4X (see below) into the specification of the language Javascript, JSON remains the means simplest to reach data, since each flow JSON is anything else only one serialized JavaScript object. Moreover, in spite of its historical link (and technique) with Javascript, JSON remains a format of structured data, and perhaps used easily by all the computer programming languages.
All these reasons are probably the cause of the existence of acronym AJAJ, in margin of AJAX, where format JSON is used in the place of format XML, for identical results.
Events
Javascript makes it possible to control the events occurring in the context of a document. These events sont :
- onabort - if there is an interruption in the loading
- onbeforeunload - when one closes the window of the navigator Web
- onblur - with the loss of the x-ray
- onchange - with the loss of x-ray if the value changed
- onclick - on a simple click
- ondblclick - on a double click
- onerror - in the event of error during the loading of the page
- onfocus - the element takes x-ray (or becomes active) the
- onkeydown - when one presses on a key
- onkeypress - when one remains supported on a key
- onkeyup - when one slackens a key
- onload - after the end of the loading of the page
- onmousedown - when that one clicks
- onmousemove - when one moves the mouse
- onmouseout - when the mouse leaves the element
- onmouseover - when the mouse is on the element
- onmouseup - when one slackens the button of the mouse
- onreset - when one clicks on a button of the " type; reset" of a form
- onresize - when one redimensionne the window
- onselect - when one selects text
- onsubmit - when one clicks on a button of the " type; submit" of a form
- onunload - when one leaves the page in progress
Events waiter
WHATWG currently works on a technology making it possible to associate administrative of events with events initiated by the waiter. Those allow, in manner " propre" , to conceive customer-server applications, and to modify the contents of a page either according to the actions of the user but of events managed by the waiter. The first navigator implementing this possibility is Opera (version 9), like announced in Event Streaming to Web Browsers.
Other uses
JavaScript can also be used as computer programming language on a Serveur HTTP. Initially, he was proposed on the waiters of Netscape, distributed thereafter by Sun Microsystems under the names iPlanet and Sun ONE , but JScript can also be used on the waiters IIS of Microsoft. JScript can serve besides for scripter a platform Microsoft Windows via WSH.
One can still quote ActionScript, used in Macromedia Flash which is also an implementation of ECMAScript. It makes it possible to handle all the elements of animation, regarded as objects.
Javascript is finally used in the platform of development Mozilla, on which several software like navigators Web is based, for tasks relating to the user interface and of communication (Exemple  interns;: the extensions of Firefox and Thunderbird are installed containing files Xpi using the Javascript. See also Prefs.js).
Depuis 2004, the " object; js" graphic environment of programming Max/MSP, makes it possible to open a window to program in Javascript, within a program Max/MSP.
JavaScript is also used in contents BIFS for the exploitation of the events. For that specification BIFS provided a node Script to incorporate of ECMAScript.
Javascript can be used for scripter the applications Adobe (Photoshop, It…) what makes it possible to have scripts independent of the platform (Mac/Windows).
It should be also known that JavaScript is also usable in Shell. to see the article.
Characteristics of the language
Anonymous functions
An anonymous function is, as its name indicates it, a function which is not identified by a name.
Example 1:
// posts: this is a test
maFonction (“this is a test”);
Example 2:
Closures
The closure (closing) are a characteristic as powerful as ignored ECMAScript language. It is about the possibility, for an expression, to reach variables which are not any more with its range.
Example of closure:
VAr ajoute10 = ajoutor (10);
ajoute10 (1); // turns over 11
In the example above, the function interns ajoute10 always has access to the argument number in spite of the fact that the call to the function ajoutor is finished.
Prototypes
A prototype is a JavaScript object which is used at the time of a failure of resolution of a name on its relative object. This mechanism is a type of héritage : the heritage by prototype.
function MonPrototype () { this.a = 1; this.b = function () { return “prototype”; } this.e = 3; }
function Twinned () { this.c = 2; this.d = function () { return “class”; } this.e = 4; }
MaClasse.prototype = new MonPrototype ();
monObjet = new Twinned ();
monObjet.a; // 1 monObjet.b (); // “prototype” monObjet.c; // 2 monObjet.d (); // “classifies” monObjet.e; // 4
Separation of the instructions
Out of C, each instruction ends in a semicolon. This practice made semicolon an obligation in many languages inspired of the syntax of C.
Javascript is more flexible, making it possible at a end of line to implicitly mark the end of an instruction. The goal is to facilitate the use of the language to the inexperienced people in data-processing Programmation. But this flexibility introduces unexpected effects: return true; The parsor JavaScript includes/understands that like two instructions: return; true; whereas the programmer more probably thought of the only instruction: return true; The advanced works of programming in Javascript warn against the unexpected effects of the automatic deduction of end of instruction and advise to write a semicolon at the end of each instruction, which does not prevent the surprises when the semicolon is forgotten.
E4X
The recent versions of the implementation of the JavaScript language of SpiderMonkey support E4X It is about a native support of XML as well as native support of a syntax of access to data XML (kind of XPath)
Example: VAr xml =
Example of access to the data: xml.popup.menuitem. (@value == “New”). @onclick The example above recovers the function corresponding to the action " New". The result of the evaluation is " CreateNewDoc () "
Another example: VAr item = 2; xml.popup.menuitem.@value The result of the evaluation is " Close"
See too
- E4X
- Ajax
References
| Random links: | Prosper Garnot | Sauzelles | Jean-Pierre Ponssard | 1979 in Rugby with XV | KK Egronom Niš | Ardal_O'Hanlon |