Datasheet

Chapter 1: Introduction to JavaScript
4
the language ( http://www.slideshare.net/jeresig/building-a-javascript-library ). It goes
something like this:
Object references are everywhere: Most useful operations involve passing references to very
large objects like the DOM (Document Object Model) or an element on the page or a function.
The DOM itself is a very large hierarchical collection of object and element references that can be
manipulated as easily as setting a property.
You can make your own objects and namespaces: Indeed, one of the first things developers
realize is that JavaScript is OO (Object Oriented) programming. While they may not fully
understand all the OO features available to them, they begin by making some basic APIs that
follow very elementary OO principals.
Object prototypes let you create OO classes: Once coders understand that they can create
instances of objects and functions to build pseudo - classes, someone points out the prototype
constructor to them and somewhere in the learners brains a light goes off. They begin building
elaborate class - based APIs for every imaginable purpose but begin hitting roadblocks related to
scope and maintaining object references between pieces of their programs.
Closures are God: As Resig pointed out in his now - famous talk, at this stage coders generally
discover how closures can help solve some of the problems encountered in stage 3 when
building complex interconnected APIs. They may not, however, fully understand the minefield
that closures are. Memory leaks, difficult - to - follow scope chains, and spaghetti code are
coexistent with a coder’s first attempts at closures.
Real - World JavaScript
As was touched on already, the JavaScript language (most often referred to by its ECMA name,
ECMAScript ) crops up all over the place not just in web pages. It also takes surprisingly different
forms depending on where it s used. To provide a complete context for the landscape of ECMAScript
use, here are some examples of these uses.
In the Browser
Browser - based development is certainly the original and predominant platform for JavaScript. JavaScript
can be executed in the context of a web page or even in the form of a browser plug - in in the case of
Firefox plugins. Web developers certainly have a lot to contend with. First and foremost, they ve got to
decide which browsers and platforms make up their audience. If they re developing sites for desktop
browsers, at least three targets should be tested: Internet Explorer, Firefox, and Safari. They ll also want
to test all of the most popular versions of these browsers (which usually doesn t mean the latest version).
For most purposes, the core language of JavaScript differs little among the latest versions of these, and
thankfully they function much the same way whether they re running on a Mac or PC. Where it gets a
little complicated is if they want to include mobile platforms as well, cell phones and gaming consoles in
particular. A lot of cell phones use the Opera browser platform, as does the Nintendo Wii browser.
Blackberry phones use their own proprietary browser and JavaScript engine, and Apple s iPhone uses a
trimmed down version of Safari.
CH001.indd 4CH001.indd 4 6/25/09 7:53:15 PM6/25/09 7:53:15 PM