Functions to create and call functions and evaluate expressions.
Methods
-
<static> closure(action [, paramList] [, context] [, settings])
-
Create function that executes specified function with given parameters and context and returns result of call.
Parameters:
Name Type Argument Description action
function Target function that will be executed when created function is called.
paramList
Array <optional>
Array-like object representing parameters that should be passed into the target function specified in
action
argument.context
Object <optional>
Object that will be used as
this
value when calling the target function specified inaction
argument. Default value isnull
.settings
Object <optional>
Operation settings. Keys are settings names, values are corresponding settings values. The following settings are supported:
ignoreArgs
:Boolean
- Whether arguments passed into the created function should be ignored. Default value isfalse
and means that arguments will be included in parameters list for the target function depending of the value ofprependArgs
setting.prependArgs
:Boolean
- Whether arguments passed into the created function should be passed into the target function before parameters specified inparamList
argument. Default value isfalse
and means that parameters list for the target function will contain values fromparamList
argument followed by arguments passed into the created function (this is similar toFunction.prototype.bind
behavior).
Returns:
Created function.
- Type
- function
-
<static> createDelegateMethod(delegate, sMethod [, settings])
-
Create function that executes specified method of the given object.
Parameters:
Name Type Argument Description delegate
Object Object whose method will be executed when created function is called.
sMethod
String Name of method that will be executed.
settings
Object <optional>
Operation settings. Keys are settings names, values are corresponding settings values. The following settings are supported:
destination
:Object
- target object into which the method will be added that should be used to access the created functiondestinationMethod
:String
- name of method of the target object that will be used to access the created function; the value ofsMethod
parameter by default
Returns:
Created function.
- Type
- function
-
<static> createFunction(sCode [, settings])
-
Create function to further use.
Parameters:
Name Type Argument Description sCode
String Function's code.
settings
Object <optional>
Operation settings. Keys are settings names, values are corresponding settings values. The following settings are supported (setting's default value is specified in parentheses):
debug
:Boolean
(false
) - specifies whether simple means for debugging should be added into function; whentrue
value is specified (debug mode), the function's code is enclosed intry
statement; the correspondingcatch
block containsconsole.log
statement to display message (namely, value ofdebugMessage
setting) and details about errordebugFunc
:String
(console.log
) - expression specifying a function that should be used to process error when the error is caught in debug mode; the expression should be resolvable in global scope; debug message (value ofdebugMessage
setting) and error object will be passed into the functiondebugMessage
:String
(Error in created function:
) - specifies message that should be shown/passed before data about error when the error is caught in debug modeexpression
:Boolean
(false
) - specifies whether function's code is an expression; whentrue
value is specified,return
statement is added at the beginning of function's codeparamNames
:String
(''
) - specifies names of function parametersscope
:Boolean
(false
) - specifies whether function's code should be wrapped inwith
statement; the value of function's first parameter is used as expression forwith
statement
Returns:
Created function.
- Type
- function
-
<static> evalWith(sExpression [, context] [, scope])
-
Calculate/evaluate value of specified expression using given context and scope.
Parameters:
Name Type Argument Description sExpression
String Expression whose value should be calculated.
context
Object <optional>
Object that should be used as context (
this
) when expression is evaluated.scope
Object <optional>
Object that should be used as scope when expression is evaluated.
- See:
Returns:
Result of expression evaluation.
- Type
- Any
-
<static> map(funcList [, paramList] [, context] [, settings])
-
Call each function from specified list and return array containing results of calls.
Parameters:
Name Type Argument Description funcList
Array Target functions that should be called.
paramList
Array | function <optional>
Parameters that should be passed into each target function. If function is specified it should return array that will be used as parameters for target functions. The following parameters will be passed into the function:
- a target function for which parameters list should be returned
- index of the target function
- array of all target functions
context
Object | function <optional>
Object that will be used as
this
value when calling each target function. Default value isnull
. If function is specified it should return object that will be used asthis
value. Parameters of the function are equal to parameters ofparamList
function (see above).settings
Object <optional>
Operation settings. Keys are settings names, values are corresponding settings values. The following settings are supported:
funcContext
:Boolean
- Whether function that is specified ascontext
parameter should be used directly asthis
value. Default value isfalse
.
Returns:
Results of functions calling.
- Type
- Array