Datasheet
Chapter 1: Introduction to JavaScript
12
Things you can ’ t do with JavaScript in a browser:
Manipulate files on the file system: A script cannot arbitrarily open and read files on a user ’ s
hard drive.
Talk directly to hardware: You can ’ t write a program that interacts directly with game
controllers or other external hardware.
Read freely from memory: You can ’ t access anything in the computer’s memory beyond its
immediate stack of local variables and what ’ s in the object model.
Perform general networking: Without using a plugin, you can ’ t open sockets or perform
general networking tasks beyond what is possible via a simple HTTP request.
Interact with the desktop: JavaScript cannot be used to open or close windows or programs on
the users ’ desktops, unless they are browser windows.
Open windows that are too small: As a result of unwholesome techniques employed by online
advertisers in the past, there are tight restrictions on the sizes and positions of windows that can
be opened by JavaScript calls.
Set the value of FileUpload fields: Owing to security restrictions, you can ’ t set the value of
FileUpload form fields.
Provide access to rich media without the use of plugins: Although I previously stated you
could create free - form graphic elements on the fly, this is only partly true. It ’ s true when users
have the necessary plugins available (i.e.: Flash). Otherwise, you would not be able to play a
sound or movie file or do rich graphics on the page.
The simple answer to when you should use JavaScript is that you should use it whenever you deem that
nobody in your audience is harmed (through compatibility problems, accessibility, or performance) and
indeed most people will benefit. While this is a decidedly cryptic response, the truth is that there is a lot you
can do with JavaScript to make applications easier, faster, and more enjoyable for everybody. Provided
you are using the least - harm philosophy in your development, aim high – – your users will thank you!
Major JavaScript Engines
The feature inside a browser that interprets all the JavaScript on a page is called the JavaScript Engine .
This is different from the feature inside a browser that renders HTML and CSS, which is known as the
Layout Engine . There are nearly as many engines as there are browser vendors. This has been the source
of a lot of confusion over the years because more often than not, it is less important to a developer which
browser someone is using than it is what JavaScript or Layout engine they are using.
Generally speaking, JavaScript engines implement a single or sometimes multiple versions of the
ECMAScript standard. With few exceptions, most modern engines are compliant up to edition 3 of this
standard. However, all the major vendors (Microsoft, Mozilla, WebKit) have developed custom
extensions to the language and to the object models which are in varying stages of support in competing
engines despite the fact that they are not part of the “ official ” standard.
In some cases (for example, in the case of Mozilla ’ s Rhino and SpiderMonkey engines), the code
implementing JavaScript is modular and can be used by third parties outside of a browser. This has
❑
❑
❑
❑
❑
❑
❑
❑
CH001.indd 12CH001.indd 12 6/25/09 7:53:19 PM6/25/09 7:53:19 PM