Non-number and negative subscripts are treated as hash keys. (Kind
of nuts. PHP is nuts in a similar way.)
Functions
Normal function definition
function name(arg1, arg2, ...) {
statements
}
Anonymous lambda function assigned to a variable
var f = function(arg1, arg2, ...) {
statements
}
The second is a lambda, which are becoming more common in many languages. This lambda
closure is then assigned to a variable, but they are often passed as parameters.
Arguments passed in the same way Java does, by value for simple
things and by reference value for objects.
Functions may be called with fewer arguments than parameters, and
the extra arguments get undefined.
Functions always have an arguments object, which is an
array of all arguments sent.
Functions may be called with more arguments than parameters. This
can be used to access extras.
Default values are allowed. Default is used instead of undefined
if the parameter is not sent.
function(a,b, ...rest)
Assigns the third and following parameter to the array-like rest.
var f = (arg1, arg2, ...) => { statements }
Also creates a function, with some technical differences we'll get to
later.
Can omit the brackets for one statements.
Object constants.
Object constants are key/value lists, much like hashes in other languages.
var x = { frank: 10, bill: 30, sally: "string" };
x.bill
Some fields can be functions, which are methods of the objects.
Method functions refer to their own fields with this
Far more to say about objects.
Objects can be created by functions.
function joe(i) {
this.size = i;
this.log = function() { console.log("My size is " + this.size); }
}
var j = new joe(12);
j.log();