module:lang/closure

The representation of a JavaScript function.

Constructor

new module:lang/closure(func, varMapping, source, funcProperties)

Create a Closure.

Parameters:
NameTypeDescription
funcfunction
varMappingobject
sourcestring
funcPropertiesobject

Members

isLivelyClosure

Properties
TypeDescription
boolean

Methods

(static) fromFunction(func, varMappingopt) → {Closure}

Converts a given func into a Closure.

Parameters:
NameTypeAttributesDescription
funcfunction

The function to derive the closure from.

varMappingobject<optional>

The variable bindings for the closure.

Returns:
Type: 
Closure

(static) fromSource(source, varMappingopt)

Creates a Closure from a JavaScript source string.

Parameters:
NameTypeAttributesDescription
sourcestring

The source code defining the function.

varMappingobject<optional>

The variable bindings for the closure.

Closure

asFunction() → {function}

Returns the function represented by the closure.

Returns:
Type: 
function

getFunc() → {function}

Retrieve the original javascript function this closure represents.

Returns:
Type: 
function

getFuncProperties() → {object}

A function may have state attached. This returns the stored properties.

Returns:
Type: 
object

getFuncSource() → {string}

Returns the source code of the closure.

Returns:
Type: 
string

hasFuncSource() → {boolean}

Wether or not the closure has the source code of the function stored.

Returns:
Type: 
boolean

lookup(name) → {*}

Lookup the binding of a given variable name.

Parameters:
NameTypeDescription
namestring

The name of the variable.

Returns:

The value the variable is bound to.

Type: 
*

recreateFunc() → {function}

Creates a real function object.

Returns:
Type: 
function

setFuncProperties() → {object}

Attaches state to the function.

Returns:
Type: 
object

setFuncSource(src)

Sets the source code of the closure.

Parameters:
NameTypeDescription
srcstring