Programming Microsoft ASP.NET 4 - Dino Esposito [469]
Anyway, today JavaScript still lives for the browser and within the browser. This is the starting point to understand what the language is for and where to look for possible (and really useful) extensions. Not surprisingly, our quest will lead straight to jQuery—currently, a natural extension of most Web applications.
Programming within the Browser
The first appearance of JavaScript as a browser-hosted language dates back to late 1995, when the first beta of Netscape Navigator 2 was released. JavaScript was introduced to give authors of Web documents the ability to incorporate some logic and action in HTML pages. Before then, a Web page was essentially a static collection of HTML tags and text. Historically, the first significant enhancement made to the syntax of HTML was the support for tags to include script code.
Original Goals of the Language
JavaScript was not designed to be a classic and cutting-edge programming language—not even by the standards of 15 years ago. The primary goal of its designers was to create a language that resembled a simpler Java that could be used with ease by inexpert page authors.
To some extent, the design of JavaScript was influenced by many languages, but the predominant factor was simplicity. It was named “JavaScript” because the language was essentially meant to be a powerful language like Java, but focused on scripting. No other relationships, beyond the deliberate reference in the name, exist between Java and JavaScript.
As a result, JavaScript is an interpreted and weakly typed language that also supports dynamic binding and objects. JavaScript, however, is not a fully object-oriented language.
Note
Originally developed at Netscape by Brendan Eich, JavaScript was first named LiveScript. The name was changed to JavaScript when Netscape added support for Java technology in its Navigator browser. The script suffix was simply meant to be the script version of an excellent programming language like Java. In no way was the language supposed to be a spinoff of Java.
Later, Microsoft created a similar language for its Internet Explorer browser and named it JScript to avoid trademark issues. In 1997, JavaScript was submitted to the European Computer Manufacturers Association (ECMA) International for standardization. The process culminated a couple of years later in the standardized version of the language named ECMAScript.
The Scripting Engine
Being an interpreted language, JavaScript requires an ad hoc run-time environment to produce visible effects from the source code. The run-time environment is often referred to as the browser’s scripting engine. As such, the JavaScript run-time environment can be slightly different from one browser to the next. The result is that the same JavaScript language feature might provide different performance on different browsers and might be flawed on one browser while working efficiently on another one. This fact makes it generally hard and time-consuming to write good, cross-browser JavaScript code and justifies the love/hate relationship (well, mostly hate) that many developers have developed with the language over the years.
The diagram in Figure 21-1 shows the overall structure of a scripting engine with an interesting extension—the JavaScript background compiler—that some of the latest browsers are implementing.
Figure 21-1. The browser’s JavaScript engine.
The scripting engine is a component that is hosted in the browser and receives the source code to process. Armed with language knowledge, the engine can resolve any name in the source code that can be mapped to a syntax element—keywords, variables, local functions, and objects.
In addition, the source code processed within a Web browser is likely populated with specific objects coming from various sources.