C

call

call function prototype function

Blah.

Function.prototype.call = function (thisObject) {
return this.apply(thisObject, Array
.prototype.slice.apply(arguments, [1]));
};

callback

The term callback is given to a function that is passed to another function or stored in an object with the intention that it be called at a later time. Callbacks are commonly used in subscription patterns where functions are to be called when some event has occurred. In browser applications, an event handler function is a callback.

var statusHolder = (function () {

// Produce an object containing three functions:
//
//    getStatus(): get the value of a private status variable.
//
//    addCallback(callback): subscribe a function that will be
//        called when the status changes.
//
//    setStatus(newStatus): Change the status and inform the
//        subscribers.

    var status,              // The private status variable.
        subscribers = [];    // The list of subscribing functions.
    return {
        getStatus: function () {
            return status;
        },
        addCallback: function (callback) {
            subscribers.push(callback);
        },
        setStatus: function (newStatus) {
            status = newStatus;
            subscribers.forEach(function (callback) {
                callback(status);
            });
        }
    };
}());

cascade

An object's methods return the same object... Blah.

case reserved word

Also see switch statement.

In many of the world's writing systems (including Latin, Greek, Cyrillic, and Armenian), letters come in two forms: lower case (or small or minuscule) and upper case (or big or capital or majuscule). For the purpose of spelling, the two cases are equivalent, but in usage the cases are distinct and Unicode gives then unqiue character codes, so while I and i are the same letter, they are different characters and have different codes.

'I' === 'i'    // false

This language is case sensitive. Case in names and strings case is significant, so 'cat' and 'Cat' are not the same string and getElementById and getElementByID are not the same name. Every reserved word is entirely lower case.

For each lower case letter there is a unique upper case letter, and for each upper case letter there is a unique lower case letter, with the following exceptions:

The toLowerCase String prototype function produces a string in which all of the upper case letters are replaced with their lower case equivalents, so 'VISA'.toLowercase() produces 'visa'. The toLocaleLowerCase String prototype function produces a string in which all of the upper case letters are replaced with their lower case equivalents using the local convention, so for programs in a Turkish environment, 'VISA'.toLocaleLowerCase() might produce 'vısa'.

These functions are aware of case:

In regexp pattern matching, the matching of letters is case sensitive. The regexp flag i makes the matching of letters case insensitive.

/v/.test('VISA')     // false
/v/i.test('VISA')    // true

The reserved word case is used for a completely unrelated purpose in the switch statement.

catch reserved word

See try statement.

ceil

ceil Math function ceiling

The Math.ceil(number) function converts a number into an integer. If the number argument is already an integer, it simply returns the number. Otherwise, it returns the lowest integer that is greater than the number. If the number is less than 0 but greater than -1, the result is -0. The function could be implemented like this:

Math.ceil = function (number) {
    return -Math.floor(-number);
};

character

Blah.

charAt

charAt String prototype function

Blah.

charCodeAt

charCodeAt String prototype function

Blah.

circular definition

See definition, circular.

class reserved word

closure

Blah.

code point

Blah.

code unit

Blah.

comment

A comment is text in a compilation unit that is ignored by the compiler. A comment can be used to document a program, giving information about its construction and operation. There are two forms of comment, the // comment and the /* block comment.

It is important to document programs to help a reader (perhaps future you) understand how the program works. It is even more important to keep comments uptodate. Incorrect comments are worse than no comments.

compilation unit

A program is delivered as one or more compilation units. In an HTML application, each <script> tag delivers one compilation unit. Scripts are compiled and executed immediately. The result of the execution could be to output a solution. More commonly, however, the result of execution is to create and modify objects in the global environment, setting up callback functions that will execute later in response to user actions and other events. For example, in a web browser, each compilation unit will be attaching event handlers to DOM nodes and installing global objects and functions that will provide services to the event handlers. The program does not stop when the compilation units have finished running. From the user’s perspective, that is when the program starts.

A compilation unit contains a sequence of zero or more statements. The statements are executed sequentially. After a statement has finished executing, the next statement is executed. After executing the last statement, the compilation unit's turn is finished, at which time another compilation unit might be exececuted, or an event might be fired.

A compilation unit executes in a global scope, so every variable created by the var statement or function statement will be global. There is a phenomenon called hoisting that can alter the sequential flow of the compilation unit. Hoisting affects the var statement and the function statement. Every global variable created by one compilation unit will be available to all subsequent compilation units.

In an HTML application, each on- event attribute delivers a deferred compilation unit. Each on- event attribute is compiled and executed when an event is dispatched. Use of on- event attributes is not recommended.

compiler

A compiler is a program that translates a source program into an executable form. In this language, the compiler can be accessed by the eval global function and the Function global function.

concat

concat array prototype function

Blah.

concat string prototype function

Blah.

conditional statement

A conditional statement alters the flow of a program, which normally executes from top to bottom, by selecting one path from two or more possibilities, deciding based on the value of an expression or the occurence of an exception.

const reserved word

constant

A constant is a name with a fixed value. Each of these names can be used as an operand, but they may not be used as an lvalue.

Strictly speaking, Infinity, Nan, and undefined are not constants, but are global variables. Bad things could result from attempting to change their values.

continuation

Blah.

continue reserved word

continue statement

Blah.

constructor

constructor function

Blah.

constructor function prototype function

A constructor is a function that is used to create new objects. A constructor should always be invoked with the new prefix operator. If a constructor is invoked without the new prefix operator, then the this parameter will not be bound to a new object. A constructor has a prototype Function prototype object that is used as the prototype of the new object. See invocation.

copy

copy array

Blah.

copy object

Blah.

correspondence

The correspondence between the variables of a function and the parameters of an inner function.

function frick(n) {
    var result = 1;
    while (n > 1) {
        result *= n;
        n -= 1;
    }
    return result;
}

function frack(n) {
    return (function (result) {
        while (n > 1) {
            result *= n;
            n -= 1;
        }
        return result;
    }(1));
}

The functions frick and frack both compute the factorial function. They produce the same result, but frick declares a variable called result, and frack uses the result of an immediate function that has a parameter called result. This demonstrates the correspondence between variables and parameters.

Holds for expressions except for this and arguments. Renaming as that and them. Holds for statements except return, break, and continue, and var and function. Blah.

cos

cos Math function cosine

The Math.cos(radians) function, also known as cosine, takes an angle in radians and returns a number in the range -1...1.

function rotate(polygon, radians) {

// This function takes an array of points, and returns another array
// of points rotated around the origin.

    var cos = Math.cos(radians),
        sin = Math.sin(radians);

    return polygon.map(function (point) {
        return {
            x: point.x * cos - point.y * sin,
            y: point.x * sin + point.y * cos
        };
    });
}

This is an approximate implemention of Math.cos:

Math.cos = (function () {
    var half_pi = Math.PI / 2;
    return function cos(radians) {
        return Math.sin(radians + half_pi);
    };
}());

See Math function.

cr

See line terminator.

create

create Object function

Blah.

CSS

Cascading Style Sheets. Blah.

curly brace

See { left curly brace and } right curly brace.

curry

Blah.

function curry(func) {
    var args = Array.prototype.slice.apply(arguments, [1]);
    return function () {
        return func.apply(null, args.concat(Array.prototype.slice.apply(arguments)));
    };
}

function add(a, b) {
    return a + b;
}

var inc = curry(add, 1);

alert(inc(6));