Professional Documents
Culture Documents
Andr Odendaal
Background
Netscape Navigator
Designed by Brendon Eich in 1995 Built to replace Java for the web and be easy to use Principles from Java (syntax), Self (prototypes) & Scheme (functional) Rushed to market with good, bad & questionable design choices Microsoft created Jscript, a compatible dialect to avoid trademark issues
ECMA
Standardized by ECMA (European Computer Manufacturers Association) Called ECMAScript between Netscape & Microsoft Latest version 5 includes strict mode for more thorough error checking
Basic Types
number
Only 64-bit floating point No integers, longs, doubles, signed or unsigned to complicate matters Associative Law does not hold for some values (a + b) + c === a + (b + c)
string
0 or more 16-bit Unicode (UCS-2) characters. No character type
boolean
true & false
Objects
Object Literals
Dynamic (not based on pre-defined class) collection of properties Property names must be a unique string within the object
Property
Named collection of attributes ES5 added functionality to define properties and added Get, Set functions Attributes: value, writable, configurable, enumerable, get, set
Demo Objects
Object Types
Arrays
Special object with index as property names (not associative) Has properties like: length, sort(), filter()
RegEx
Regular expression object 2 primary methods exec() returns a match and test() returns boolean
Functions
An object which can be invoked with parentheses ()
Other Types
null
Nothing
undefined
Less than nothing
Functions
Composition
Made up of 4 parts: function, name (optional), parameters, set of statements 2 additional parameters: arguments object & this (invocation context)
Invocation
Method this is the local object Function this is the global object Apply this is passed as a parameter Constructor this is the new object
Calling
Assigning less parameters will make them undefined
Inheritance
If object doesnt have a property look in base object
Demo - Prototyping
Questions?