Namespace MochiKit.Base
Provides functional programming and useful comparisons.
Defined in: Base.js.
Constructor Attributes | Constructor Name and Description |
---|---|
Method Attributes | Method Name and Description |
---|---|
<static> |
MochiKit.Base.defaultValue()
Returns the first function argument that is not undefined.
|
<static> |
MochiKit.Base.dict(itemsOrKeys, values)
Creates a dictionary object from a list of keys and values.
|
<static> |
MochiKit.Base.functionName(func)
Returns the name of a function.
|
<static> |
MochiKit.Base.injectStackTrace(stackTrace, func)
Injects a stack trace for a function.
|
<static> |
MochiKit.Base.mask(src, keys)
Filters an object by removing a list of keys.
|
<static> |
MochiKit.Base.registerFunctionNames(obj, name, stack)
Registers function names for debugging or logging.
|
<static> |
MochiKit.Base.resolveURI(uri, base)
Resolves a relative URI to an absolute URI.
|
<static> |
MochiKit.Base.select(src, keys)
Creates a new object by copying keys and values from another
object.
|
<static> |
MochiKit.Base.stackTrace(maxDepth)
Returns the current execution stack trace.
|
Method Detail
<static>
{Object}
MochiKit.Base.defaultValue()
Returns the first function argument that is not undefined.
- Parameters:
- {Object} ... Optional
- the values to check
- Returns:
- {Object} the first non-undefined argument, or undefined if all arguments were undefined
<static>
{Object}
MochiKit.Base.dict(itemsOrKeys, values)
Creates a dictionary object from a list of keys and values. It
can be used either as a reverse of items(), or as a reverse of
keys() and values(). That is, either the function take a single
list where each element contains both key and value, or it takes
two separate lists, one with keys and the other with values. If
a key is specified twice, only the last value will be used.
- Parameters:
- {Array} itemsOrKeys
- the list of items or keys
- {Array} values Optional
- the optional list of values
- Returns:
- {Object} a dictionary object with all the keys set to the corresponding value
<static>
{String}
MochiKit.Base.functionName(func)
Returns the name of a function. This is often useful for debugging
or logging purposes. If the function is anonymous or the
JavaScript environment doesn't provide function
name
properties, any registered function name or undefined will be
returned.
- Parameters:
- {Function} func
- the function to name
- Returns:
- {String} the function name, or undefined if not available
<static>
MochiKit.Base.injectStackTrace(stackTrace, func)
Injects a stack trace for a function. This method is useful for
creating a fake stack trace in anonymous or callback functions. A
null value can be used to clear any previously injected stack
trace for the calling function.
- Parameters:
- {Array} stackTrace
- the stack trace, or null to clear
- {Function} func Optional
- the function to modify, or null for the currently executing function (i.e. the caller)
<static>
{Object}
MochiKit.Base.mask(src, keys)
Filters an object by removing a list of keys. A list of key names
(or an object whose property names will be used as keys) must be
specified as an argument. A new object containing the source
object values for the specified keys will be returned. The source
object will be modified by removing all the specified keys.
- Parameters:
- {Object} src
- the source object to select and modify
- {Array/Object} keys
- the list of keys to remove, or an object with the keys to remove
- Returns:
- {Object} a new object containing the matching keys and values found in the source object
<static>
MochiKit.Base.registerFunctionNames(obj, name, stack)
Registers function names for debugging or logging. This is useful
when using anonymous functions or inside JavaScript environments
that do not provide function
name
properties. This
function will add the specified name as a new NAME
property to any function that doesn't already have a name. This
function will also process any properties or prototype properties
recursively adding names like name.[property name]
.
- Parameters:
- {Object} obj
- the function or object to register
- {String} name
- the function or object (class) name
- {Array} stack Optional
- the object stack to avoid circular recursion
<static>
{String}
MochiKit.Base.resolveURI(uri, base)
Resolves a relative URI to an absolute URI. This function will
return absolute URI:s directly and traverse any "../" directory
paths in the specified URI. The base URI provided must be
absolute.
- Parameters:
- {String} uri
- the relative URI to resolve
- {String} base
- the absolute base URI
- Returns:
- {String} the resolved absolute URI
<static>
{Object}
MochiKit.Base.select(src, keys)
Creates a new object by copying keys and values from another
object. A list of key names (or an object whose property names
will be used as keys) must be specified as an argument. The
returned object will only contain properties that were defined in
the source object, keeping the source object values. The source
object will be left unmodified.
- Parameters:
- {Object} src
- the source object to select values from
- {Array/Object} keys
- the list of keys to select, or an object with the keys to select
- Returns:
- {Object} a new object containing the matching keys and values found in the source object
<static>
{Array}
MochiKit.Base.stackTrace(maxDepth)
Returns the current execution stack trace. The stack trace is an
array of function names with the innermost function at the lowest
index (0). Due to limitations in the JavaScript API:s, the stack
trace will be cut if recursion is detected. The stack trace will
also be cut if the call depth exceeds the maximum depth or if any
function in the chain has an injected stack trace.
- Parameters:
- {Number} maxDepth Optional
- the maximum call depth, defaults to 20
- Returns:
- {Array} the stack trace array of function names