Naked JavaScript

Taking the DOM off JavaScript 
 
Filed under

javascript

 

Getting Started

Before beginning, we should make sure that we are all here for the right reasons. JavaScript is commonly only thought of as a scripting language confined the browser space and riddled with "landmines". Both statements, as we shall see throughout this series, are completely false descriptions of the language and its the intention of these posts to change your view. So that is our goal, to learn the wonders, beauty, and a little bit of magic that you can accomplish with a language that you will use or at least could be using in nearly every project with little effort. 

I could go on to laud about how elegant and beautiful JavaScript is, but that really doesn't help anyone. At this point I am going to assume you have some degree of interest in the language and have been exposed to at least one other programming language. A final "clarification", in order to expedite these posts to you, I am going to limit the operating system environment to Mac OS X and Linux. If you are a reader using a Windows machine, all of the examples after installation should work perfectly. Please leave a comment with any notes on how to accomplish the same installation results in Windows if there are any differences and we will add them as part of procedures.

Without further ado, lets get JavaScripting.

Getting JavaScript

Unlike other programming texts you might be familiar with, the "configuration step" before we get to "Hello World" is going to be rather long. The length of this post is mainly because we are going to set up the full spectrum of JavaScript interpreters. For the first examples we will be going through, you will not need all of the JavaScript interpreters, so if you want to "Quick Start", just follow the instructions for Rhino. We will be using all of these interpreters as part of the series, mainly because the projects that use them take advantage of specific features each offers. I recommend pulling down all of them and playing around with each, it will be quite exciting. Each post will begin with an identifier of which JavaScript engine can be used for that particular example as well as a link to install that engine, so if you want you can install the engine only when needed.

The following are the interpreters we will be installing and using as part of this series:

  • Rhino - A Java based JavaScript engine from Mozilla this is probably the most widely deployed and used non-browser JavaScript interpreter available. As such it is also the easiest to begin playing with Naked JavaScript in and the most robust base implementation. That said, the newer implementations mentioned below are pushing the envelope in terms of what JavaScript can do. They provide new features (Web Workers, etc.) that Rhino has yet to implement. If you are looking for the quickest, most risk-free start, Rhino is your best bet.
  • SpiderMonkey - A C based JavaScript engine from Mozilla. This interpreter is the main JavaScript engine that has been used in Mozilla products, including Firefox, up until version 3.5 which will include a revised interpreter named TraceMonkey.
  • TraceMonkey - A massive extension of SpiderMonkey that leverages the power of Trace Trees for Just In Time (JIT) native code compilation process which in turn drastically improves performance on the order of 3 to 30 times. TraceMonkey includes various improvements to the overall processing and handling of JavaScript as well as integrating the newest features including better garbage collection and various integrations from the Tamarin project, an open source ActionScript Virtual Machine built as a collaboration between Mozilla and Adobe.
  • V8 - A C++ based JavaScript engine built by Google as part of the Google Chrome web browser. Google's team openly focuses on making V8 a high performance engine by applying deep virtual machine technology to the entire workflow of JavaScript interpretation and processing. Google developed V8 for a variety of reasons, but mainly because of a firm belief that high performance JavaScript engines are critical for future innovations
  • SquirrelFish Extreme - Also known as JavaScriptCore, WebKit's JavaScript engine which was one of the first "performance" contender's to Mozilla's general dominance. Apple uses WebKit and JavaScriptCore to produce Safari, their lightning fast web browser for both desktop and mobile web browsing. Mobile Safari for the iPhone brought full featured mobile web browsing to the general public and was the first time that a vender recommended the creation of pure HTML, CSS, and JavaScript for application development. Palm went a step further with WebKit as part of building the Palm Pre by using HTML, CSS, and JavaScript throughout the entire Operating System stack and their Mojo SDK.

There are other JavaScript engines out there, but for the sake of discussions in this series, these will be the main engines that we use. The next several posts will help you with install each engine. It is recommended that in order to keep them all straight you create a directory named "javascript", without the quotes. While you can put this directory anywhere, the examples will assume the directory is off of your home directory. To create this directory enter the following commands:

  mkdir ~/javascript && cd ~/javascript 

And you are off to installing.

Filed under  //   javascript   js   quickstart   rhino   squirrelfishextreme   tamarin   tracemonkey   v8   webkit  

Comments [0]

Preface

JavaScript is a multi-paradigm, prototype-based, functional scripting language or in short it is one of the most advanced languages that nearly every one knows, but very few know deeply. It combines the elegance of functional programming with the ease and rapid development capabilities of scripting languages. While it is most commonly thought of as a client side scripting language confined to the browser environment, JavaScript has far more to offer the world than just being the widest deployed language in the computer world. In the traditional model of JavaScript, the Document Object Model or DOM is often the focal scope or reason for working with the language in order to update elements within a web browser. This series is not going to deal with the DOM at all - I recommend reading JavaScript: The Good Parts by Douglas Crockford and JavaScript: The Definitive Guide by David Flanagan if you are interested in the DOM, well actually just read those books regardless. This series will introduce to some of the deep concepts touched on by those authors as well as introduce you to some of the most exciting and cutting edge concepts in JavaScript. We will go through how to install JavaScript and use it outside the browser, but you can also follow along directly in your browser if so inclined. This series is being done in blog posts in order to keep up with the rapidly changing world of JavaScript. 

Why Should I Learn JavaScript as a Language?

Consider that nearly every computer since the mid 1990s has come equipped with a some form of a JavaScript interpreter and that since that time period nearly every major technology vendor has heavily funded the further development of the language, both in terms of speed and functionality. That fact catches most people off-guard, because JavaScript is often thought of by developers as a necessary evil and by some as just plain evil. This misconception has evolved over the years from being burned by the wide variety of implementations, each with their own oddities, issues, and functionalities; much of which has been resolved, fixed, or handled for the developer by frameworks, libraries, or improvements in the interpreter. The JavaScript community has progressed towards a set of standard APIs and language definitions, most of which conforming to the ECMAScript ECMA-262, Edition 3 standard. At this point, the world of JavaScript is not only stable, it is also extending well beyond the browser and into the desktop, mobile, and server environments, each of which is stabilizing on appropriate APIs and domain specific definitions.

The best part about all of these advancements is that you most likely know enough JavaScript to start programming for all of these environments right now. JavaScript is one of the more approachable languages for both developers and non-developers alike and that is one of its strong suits. The language has evolved over many years; sometimes for the better, sometimes less so; hopefully we will journey through the JavaScript language with ease and grace while learning many amazing things that will hopefully positively re-enforce or change your view of this advanced language.

By working through the concepts and examples in this series, you will learn a wide variety of techniques and programming practices for JavaScript, may of which will be applicable in other programming languages. Even if you never use JavaScript outside the browser, the concepts that you will be exposed to as part of this series will help you with in-browser JavaScript programming. If you do any programming for the web, you are most likely going to be using JavaScript somewhere, somehow.

Why Naked?

JavaScript without the DOM is a beautiful thing. This has been said by some of the most influential JavaScript developers, but has until now been kept as a deep secret. With the increased interest around JavaScript technologies fueled by products from Adobe, Apache, Apple, Google, Microsoft, Mozilla, and Palm that do everything from browser scripting to full mobile OS development to server and database programming; there is a strong trending toward this language as more than just a browser scripting language. By learning JavaScript stripped of its DOM clothing, you can easily get to the best and most overlooked parts of the language. Also the world outside the browser is rapidly expanding and growing, which makes it rather hard to keep tabs on all the newest and most exciting updates while trying to code in-browser JavaScript (or other languages).

A Note

This series may not always "flow" from one idea to a similar idea and that is on purpose since new technologies, products, or concepts come to light in the JavaScript world all the time. We may have guest writers that can dive deep about new concepts or provide preview details about technologies, or just bounce around from technology to technology - either way it will be a fun ride. 

Enjoy

Filed under  //   javascript   js  

Comments [0]