Home » Articole » Articles » Computers » Web development » JavaScript

JavaScript

JavaScript logoParadigm: Multi-paradigm: scripting, object-oriented (prototype-based), imperative, functional, event-driven
Designed by: Brendan Eich
Developer: Netscape Communications Corporation, Mozilla Foundation, Ecma International
First appeared: May 23, 1995; 21 years ago
Typing discipline: dynamic, duck
Major implementations: V8, JavaScriptCore, SpiderMonkey, Chakra
Influenced by: Lua, Scheme, Perl, Self, Java, C, Python, AWK, HyperTalk
Influenced: ActionScript, AtScript, CoffeeScript, Dart, JScript .NET, LiveScript, Objective-J, Opa, Perl 6, QML, TypeScript

JavaScript is a scripting programming language primarily used in interactive web pages but also for servers. It is a prototype object oriented language, this is to say that the basic language and key interfaces are provided by objects that are instances of classes, but which are each equipped with constructors to create their properties, including a prototype property that allows to create custom inheritanced heirs. In addition, functions are first class objects.

JavaScript was created in 1995 by Brendan Eich. It was standardized under the name ECMAScript in June 1997 by Ecma International in the ECMA-262 standard. JavaScript is an implementation of ECMAScript, that implemented by the Mozilla Foundation. The implementation of ECMAScript is called Microsoft JScript, while Adobe Systems is named ActionScript.

Concepts

The purpose of JavaScript is to manipulate objects in a simple way, in the computer sense, provided by a host application.

Hello world

Here is the classic example of “hello world” in JavaScript, when the host application is a web browser:

alert(“Hello world”);

In the host application, alert is a method of DOM window class, but it is recurrent, it is one of the only classes which we do not have to specify the name to use its methods.

The syntax

window.alert(“Hello world”);

will therefore have exactly the same result.

Use

In a web page

JavaScript code can be embedded directly in web pages, to be executed on the client‘s post. That’s when the Web browser that supports the execution of these programs called scripts.

Usually, JavaScript is used to control the data entered in HTML forms, or to interact with the HTML document via the Document Object Model interface, provided by the browser (this is sometimes called dynamic HTML or DHTML). It is also used to perform dynamic services, sometimes futile, strictly cosmetic or for ergonomic purposes.

JavaScript is not limited for handling HTML documents and can be used to manipulate documents SVG, XUL, and other XML dialects.

Incompatibility

Netscape and Microsoft (with JScript in Internet Explorer) have developed their own variant of this language that each supports almost fully ECMAScript but has additional and inconsistent functionality, rarely used in the context of the programming of web pages. However JavaScript is often the source of problems. They are more often due to the management of different versions of the object model (DOM) provided by browsers, than the issues of language portability (the different implemented respecting relatively well ECMAScript).

Faced with this problem it is often used a construction of the type

if (myObjet.method) {
myObjet.method();
}

However, it is preferable to use a comparison on the type

if (typeof myObjet.method !== “undefined”) {
myObjet.method();
}

or better yet:

if (typeof myObjet.method === “function”) {
myObjet.method();
}

It checks this way that myObject has an implementation method that can be used. Most often, if a browser does not support the method of myObject, it manages a comparable method method2, and you can then adapt the JavaScript code to the browser that runs it:

if (typeof monObjet.methode === “function”) {
monObjet.methode();
} else if (typeof monObjet.methode2 === “function”) {
monObjet.methode2();
}

Another method is to check the server side, the browser used by the customer and to send the corresponding code. This is however not recommended because it is far better to test directly the existence, behavior of a function, of a property, etc. rather than making assumptions based on the detection of the browser.

Ajax

JavaScript is used in the Ajax (Asynchronous Javascript English And XML) method used to change the content of web pages by programming. Due to user operations, JavaScript language scripts will send requests to the Web server using the XMLHttpRequest object. Then scripts will modify the content of the web page based on the response received; the answer is in XML format and the script handles the set of DOM objects that represents the content of the page. The XMLHttpRequest, XML and DOM were added to web browsers between 1995 and 2005. Ajax method allows rich Internet applications, offering superior handling and superior comfort; it is one of the key topics of Web 2.0 movement.

JSON

JSON (JavaScript Object Notation) is a format using the notation of JavaScript objects to transmit structured information in a more compact and closer way of programming languages, than XML.

Despite the existence of the DOM and the recent introduction of E4X in the specification of JavaScript, JSON is still the easiest way to access data, since each JSON stream is nothing other than a serialized JavaScript object. Moreover, despite its historical (and technical) link with JavaScript, JSON is still a structured data format, and can be easily used by all programming languages.

Since 2009, the browsers are beginning to integrate native support of JSON format, which facilitates its manipulation, security (against assessment malicious scripts embedded in a JSON string), and the processing speed. So Firefox and IE browsers incorporate respectively from versions 3.5 and 8.

Other uses

On a web server

JavaScript can also be used as a programming language on an HTTP server like the languages PHP, ASP, etc. Besides the CommonJS project is working to specify an ecosystem for JavaScript outside of the browser (eg on the server or native desktop applications). The project was launched by Kevin Dangoor in January 2009. The CommonJS project is not affiliated with the group of Ecma International TC39 working on ECMAScript, but some members of TC39 are participating in the project.

Historically, JavaScript was proposed on Netscape servers, subsequently distributed by Sun Microsystems under the iPlanet and Sun ONE names, but JScript can be used on the Microsoft‘s Internet servers Information Services. JScript can also be used to script a Microsoft Windows platform using Windows Scripting Host (WSH).

There are also independent projects and servers Open Source implementation of JavaScript. Among them, we can distinguish Node.js, a multi-platform network application development based on the V8 JavaScript engine and CommonJS specifications.

Other supports

ActionScript, used in Adobe Flash, is also an implementation of ECMAScript. It can handle all the animation elements, considered as objects. JavaScript can be used to script other Adobe applications (Photoshop, Illustrator, …), allowing independent platform scripting (Microsoft Windows, Apple OSX, Linux …).

JavaScript is finally used in the Mozilla development platform, which are based on several software like Web browsers, for tasks related to the user interface and internal communication (eg. Firefox and Thunderbird extensions are installed in XPI file base using JavaScript).

Since 2004, the js object of the graphical programming environment Max/MSP opens a window to program in JavaScript within a Max/MSP program.

The software ImageJ and CaRMetal are provided with JavaScript consoles, which allow them to write scripts in a graphical environment. Algobox also uses JavaScript syntax for functions.

JavaScript is also used in a BIFS content for the exploitation of events. For this specification BIFS provides a Script node to incorporate the ECMAScript.

The OpenOffice.org office suite lets you use JavaScript as a macro language.

JavaScript is also usable in shell or with Vista gadgets.

Finally, JavaScript is also used to boost the QML Qt graphics library.

Leave a Reply

Your email address will not be published. Required fields are marked *