Specifications
The JavaScript function operator supports closures, for example:
function make_counter( initialValue )
{
var current = initialValue;
return function( increment ) { current += increment; return
current; }
}
// ...
var counterA = make_counter( 3 ); // Start at 3.
var counterB = make_counter( 12 ); // Start at 12.
var x1 = counterA( 2 ); // Adds 2, so x1 == 5
var x2 = counterB( 2 ); // Adds 2, so x2 == 14
var x3 = counterA( 7 ); // Adds 7, so x3 == 12
var x4 = counterB( 30 ); // Adds 30, so x4 ==44
Note that for each call to make_counter(), the anonymous function that is
returned has its own copy of current (initialized to the initialValue), which is
incremented independently of any other anonymous function's current. It is
this capturing of context that makes the function that is returned a closure.
See also function declaration and Function type.
property in Object
Returns true if the given Object has the given property; otherwise returns false.
in operator
object instanceof type
Returns true if the given object is an instance of the given type, (or of one of
its base classes); otherwise returns false.
instanceof
operator
var instance = new Type( optArguments );
This function calls the constructor for the given Type, passing it the optional
arguments (optArguments) if any and returns an instance of the given Type.
new operator
The Type may be one of the built-in types, one of the library types, or a
user-defined type.
Example:
var circle = new Circle( x, y );
var file = new File();
this.property
The "this" operator may only be used within a function that is defined within
a class, that is a member function. Within the scope of the function this is a
reference to the particular instance (object) of the class's type.
this operator
Example:
class MinMax {
var _min;
var _max;
function MinMax( min, max ) { this._min = min; this._max = max;
}
function max() { return this._max; }
397
Enfocus Switch 10










