14.07.2013 Views

Essentials of Javascript - Cultural View

Essentials of Javascript - Cultural View

Essentials of Javascript - Cultural View

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

JavaScript 3<br />

Trademark<br />

"JavaScript" is a trademark <strong>of</strong> Sun Microsystems. It is used under license for technology invented and implemented<br />

by Netscape Communications and current entities such as the Mozilla Foundation. [22]<br />

Features<br />

The following features are common to all conforming ECMAScript implementations, unless explicitly specified<br />

otherwise.<br />

Imperative and structured<br />

JavaScript supports all the structured programming syntax in C (e.g., if statements, while loops, switch statements,<br />

etc.). One partial exception is scoping: C-style block-level scoping is not supported (instead, JavaScript has<br />

function-level scoping). JavaScript 1.7, however, supports block-level scoping with the let keyword. Like C,<br />

JavaScript makes a distinction between expressions and statements. One syntactic difference from C is automatic<br />

semicolon insertion, in which the semicolons that terminate statements can be omitted. [23]<br />

Dynamic<br />

dynamic typing<br />

As in most scripting languages, types are associated with values, not variables. For example, a variable x could<br />

be bound to a number, then later rebound to a string. JavaScript supports various ways to test the type <strong>of</strong> an<br />

object, including duck typing. [24]<br />

object based<br />

JavaScript is almost entirely object-based. JavaScript objects are associative arrays, augmented with<br />

prototypes (see below). Object property names are string keys: obj.x = 10 and obj["x"] = 10 are equivalent, the<br />

dot notation being syntactic sugar. Properties and their values can be added, changed, or deleted at run-time.<br />

Most properties <strong>of</strong> an object (and those on its prototype inheritance chain) can be enumerated using a for...in<br />

loop. JavaScript has a small number <strong>of</strong> built-in objects such as Function and Date.<br />

run-time evaluation<br />

JavaScript includes an eval function that can execute statements provided as strings at run-time.<br />

Functional<br />

first-class functions<br />

Functions are first-class; they are objects themselves. As such, they have properties and can be passed around<br />

and interacted with like any other object.<br />

inner functions and closures<br />

Inner functions (functions defined within other functions) are created each time the outer function is invoked,<br />

and variables <strong>of</strong> the outer functions for that invocation continue to exist as long as the inner functions still<br />

exist, even after that invocation is finished (e.g. if the inner function was returned, it still has access to the<br />

outer function's variables) — this is the mechanism behind closures within JavaScript.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!