Friday, December 7, 2007

JavaScript Glossary

This post is currently under construction; please post any comments below.


Argument - An independent variable declared in a function's header and defined by the function's caller. An argument (or "arg") is only visible within the declared function's scope. If an argument uses the same identifier as another variable in a scope which contains the function, the argument hides the other variable.
function getArgument(arg){
alert('Your argument is ' + arg + '.');
}
getArgument('weak');// alerts "Your argument is weak."



Boolean - The binary (either true or false) datum type named after George Boole. Boolean values are immutable.


Class - A contrived notion in JavaScript which is nonetheless frequently used for transitioning class-based programmers into the prototype-based language. Classes are simulated in JavaScript via prototypes of constructors.


Constructor - A function called with new. By convention, constructor names should always be in UpperCamelCase. In the body of a constructor, the pseudo-variable this refers to each individual instance of that constructor that will ever exist.
function Foo(){
alert(this.constructor.name);
}
var foo = new Foo();//alerts "Foo"
Foo();//alerts "undefined" because this.constructor (i.e. window.constructor) doesn't exist in this case



Clone - An object which inherits every current property of its constructor's prototype.


Datum Type - One of at least 5 types of values: boolean; function; number; object; and string. The type of the literal undefined value is "undefined" but I don't consider that a real type. A value's type is returned by typeof value. See http://developer.mozilla.org/en/docs/Core_JavaScript_1.5_Reference:Operators:Special_Operators:typeof_Operator and http://en.wikipedia.org/wiki/Data_type.


Event - An object which represents a change in the browser's state; is passed as an argument to any event-handler as called by the browser.


Event-handler - A function called by the browser when a specific type of event occurs. Event-handlers can also be explicitly called by a script, but this is very uncommon.
window.onload = function (){
alert('Do something useful!');
};



Function - The datum type which represents sets of instructions to be executed by the browser at the prompting of either scripting or, in the case of event-handlers, the browser itself. Being objects, JavaScript functions are first-class. Functions are mutable.


Global - Owned by window. Global variables are accessible from every scope.


Local - Declared independently and therefore owned by no particular object.


Method - A function which happens to be the property of an object. Methods, like all other properties, should always have lowerCamelCase names (again, by widely accepted convention). In a method, this refers to the object in whose context the method was called.


Number - The signed, floating-point, numeric datum type. Numbers may be specified as either decimal, hexadecimal, or octal values. Numbers are immutable.


Object - The catch-all datum type. If a value is defined but doesn't fit in the boolean, function, number, or string groups (the members of which also being objects), then it's called an object. Object values are mutable.


Procedure - A method of no particular object (or of window). A function which is called as a property of no particular object is a local procedure; a function explicitly assigned to a property of window is a global procedure. Like methods', procedures' names should be in lowerCamelCase.


Prototype - An object whose properties are inherited by one or more clones. At its core, JavaScript is prototype-based.


String - The datum type of character sequences. Any length of non-newline characters delimited by two single- or double-quotes ( ' or " ) is a string. If a newline is interposed between the quotes, an "Unterminated string constant" error is issued. String values are immutable.

No comments: