
Object-Oriented JavaScript
By :

Initially, the web was not much more than just a number of scientific publications in the form of static HTML documents connected together with hyperlinks. Believe it or not, there was a time when there was no way to put an image in a page. However, that soon changed. As the web grew in popularity and size, the webmasters who were creating HTML pages felt they needed something more. They wanted to create richer user interactions, mainly driven by the desire to save server round trips for simple tasks such as form validation. Two options came up-Java applets and LiveScript, a language conceived by Brendan Eich at Netscape in 1995 and later included in the Netscape 2.0 browser under the name of JavaScript.
The applets didn't quite catch on, but JavaScript did. The ability to use short code snippets embedded in HTML documents and alter otherwise static elements of a web page was embraced by the webmaster community. Soon, the competing browser vendor, Microsoft, shipped Internet Explorer (IE) 3.0 with JScript, which was a reverse engineered version of JavaScript plus some IE-specific features. Eventually, there was an effort to standardize the various implementations of the language, and this is how ECMAScript was born. European Computer Manufacturers Association (ECMA) created the standard called ECMA-262, which describes the core parts of the JavaScript programming language without browser and web page-specific features.
You can think of JavaScript as a term that encompasses the following three pieces:
While there is one chapter in this book dedicated to the browser, the DOM, and the BOM, most of this book describes the core language and teaches you skills you can use in any environment where JavaScript programs run.
For better or for worse, JavaScript's instant popularity happened during the period of the browser wars I (approximately 1996 to 2001). Those were the times during the initial Internet boom when the two major browser vendors, Netscape and Microsoft, were competing for market share. Both were constantly adding more bells and whistles to their browsers and their versions of JavaScript, DOM, and BOM, which naturally led to many inconsistencies. While adding more features, the browser vendors were falling behind on providing proper development and debugging tools and adequate documentation. Often, development was a pain; you would write a script while testing in one browser, and once you're done with development, you test in the other browser, only to find that your script simply fails for no apparent reason, and the best you can get is a cryptic error message, such as operation aborted.
Inconsistent implementations, missing documentation, and no appropriate tools painted JavaScript in such a light that many programmers simply refused to bother with it.
On the other hand, developers who did try to experiment with JavaScript got a little carried away, adding too many special effects to their pages without much regard of how usable the end results were. Developers were eager to make use of every new possibility the browsers provided, and ended up enhancing their web pages with things such as animations in the status bar, flashing colors, blinking texts, objects stalking your mouse cursor, and many other innovations that actually hurt the user experience. These various ways to abuse JavaScript are now mostly gone, but they were one of the reasons why the language had something of a bad reputation. Many serious programmers dismissed JavaScript as nothing but a toy for designers to play around with, and dismissed it as a language unsuitable for serious applications. The JavaScript backlash caused some web projects to completely ban any client-side programming and trust only their predictable and tightly controlled server. And really, why would you double the time to deliver a finished product and then spend additional time debugging problems with the different browsers?
Everything changed in the years following the end of the browser wars I. A number of events reshaped the web development landscape in a positive way. Some of them are given as follows:
In this healthier environment, developers started finding out new and better ways to use the instruments that were already available. After the public release of applications such as Gmail and Google Maps, which were rich on client-side programming, it became clear that JavaScript is a mature, unique in certain ways, and powerful prototypal object-oriented language. The best example of its rediscovery was the wide adoption of the functionality provided by the XMLHttpRequest
object, which was once an IE-only innovation, but was then implemented by most other browsers. XMLHttpRequest
object allows JavaScript to make HTTP requests and get fresh content from the server in order to update some parts of a page without a full page reload. Due to the wide use of the XMLHttpRequest
object, a new breed of desktop-like web applications, dubbed Ajax applications, was born.
An interesting thing about JavaScript is that it always runs inside a host environment. The web browser is just one of the available hosts. JavaScript can also run on the server, on the desktop, and on mobile devices. Today, you can use JavaScript to do all of the following:
Node.js
, as well as code that can run using Rhino (a JavaScript engine written in Java).asm.js
format, which can then be run inside a browser.We can only speculate what the future will be, but it's quite certain that it will include JavaScript. For quite some time, JavaScript may have been underestimated and underused (or maybe overused in the wrong ways), but every day, we witness new applications of the language in much more interesting and creative ways. It all started with simple one-liners, often embedded in HTML tag attributes, such as onclick
. Nowadays, developers ship sophisticated, well-designed and architected, and extensible applications and libraries, often supporting multiple platforms with a single codebase. JavaScript is indeed taken seriously, and developers are starting to rediscover and enjoy its unique features more and more.
Once listed in the nice-to-have sections of job postings, today, knowledge of JavaScript is often a deciding factor when it comes to hiring web developers. Common job interview questions you can hear today include-Is JavaScript an object-oriented language? Good. Now, how do you implement inheritance in JavaScript? After reading this book, you'll be prepared to ace your JavaScript job interview and even impress your interviewers with some bits that, maybe, they didn't know.
Change the font size
Change margin width
Change background colour