JavaScript overview
— a 15min lecture before getting into details
-
Language features
-
interpreted OO scripting language, most commonly used in Web browsers, i.e. "client-side" scripting
-
similar syntax as Java, C/C++
-
case-sensitive, which can be confusing with working with case-insensitive HTML
-
because JavaScript objects and properties often represent HTML tags and attributes
-
optional semicolons
-
loose typing - no type associated when declaring, even declaration is optional
-
primitive types: numbers, strings, Booleans, all of which have convenient wrapper classes
-
all numbers are double-precision floating-point values
-
character is string of length 1
-
strings are compared by value in contrast by reference as in Java
-
strings are immutable in JavaScript
-
Reference types
-
objects, essentially "associative arrays" because properties are allowed to be accessed via variables
-
allowed to add or delete properties to existing object, i.e. you can extend other people's code
-
arrays
-
"thin layer" atop objects to support indexed access
-
variable length
-
mixture of values (types)
-
many array methods are inspired by Perl
-
functions are values - not only can it be defined and invoked, but also
-
assigned and stored in variables or as object properties (methods)
-
passed as arguments
-
returned by other functions
-
functions can be invoked with a different number of arguments as in its definition
-
built-in classes: Date, RegExp, Error
-
Automatic conversion is powerful, but should be used with caution
-
prototype-based inheritance
-
Pseudoclass
-
supports garbage collection
-
dialect as the standardized EMCAScript
-
JScript of IE is similar
-
Current version 1.8, but fairly stable since 1.5
-
Movement of JavaScript 2.0, strong typing, tabled for long
-
Client-side JavaScript
-
embedded in browser, exposed with APIs to manipulate
-
browser window
-
frame hierarchy
-
browser
-
navigation history
-
document
-
legacy DOM - HTML elements in arrays and named "forms, form elements, images, applets, links" HTML elements
-
DOM represented as a tree - you can traverse this tree
-
CSS styles
-
font, color type of representation
-
position, layer and visibility (for animation)
-
events
-
HCI events, document events, HTML events
-
forms
-
form validation
-
HTTP
-
submitted requests to Web servers w/o reloading page - a thrust behind Web apps
-
3715 has a separate lecture on Ajax
-
In what aspects is JS used in Web apps
-
How to use JSDG
-
Four parts:
-
Core JavaScript
-
Client-side scripting
-
References for core JavaScript
-
References for client-side scripting
-
Important summaries:
-
Type conversion: Table 3-3 (p39)
-
Datatype manipulation in JavaScript: Table 3-5 (p48)
-
CSS 2.1 style attributes and their names: Table 16-1 (P347)