zerk Class
Zerk Object
The Zerk main object and namespace
Item Index
Methods
- _classLoaded
- _classLoading
- _createObject
- _defineClass
- _delayDefine
- _getClassURL
- _initErrorHandler
- _loadScript
- _onLoad
- _parseClassName
- _parseMeta
- _processLoadedClass
- _ready
- _requireClass
- apply
- arrayUnique
- clone
- create
- define
- error
- exit
- inArray
- init
- isArray
- isBoolean
- isDate
- isDefined
- isEmpty
- isFunction
- isNumber
- isNumeric
- isObject
- isPrimitiveType
- log
- objectCount
- objectKeys
- objectValues
- parent
- typeOf
- warn
Properties
Methods
_classLoaded
-
className
Checks if a class is loaded and defined already
Parameters:
-
className
StringThe name of the class
Returns:
_classLoading
-
className
Checks if a class is loading already
Parameters:
-
className
StringThe name of the class
Returns:
_createObject
-
parent
Creates an object from parent object definition
This is an implementation of Douglas Crockfords prototypal inheritance in JavaScript.
Parameters:
-
parent
Object
Returns:
_defineClass
-
meta
-
body
-
callback
Defines a class
Parameters:
-
meta
ObjectClass meta object
-
body
ObjectClass body
-
callback
FunctionCallback function that fires after the class was defined
Returns:
_delayDefine
-
meta
-
body
-
callback
-
waitFor
Creates a delayed define entry and returns its handle
Parameters:
-
meta
ObjectClass meta object
-
body
ObjectClass body
-
callback
FunctionCallback function
-
waitFor
Array
Returns:
_getClassURL
-
className
Returns the url for given class name
Parameters:
-
className
StringThe name of the class
Returns:
_initErrorHandler
()
private
Initializes the error handler
_loadScript
-
url
Loads a JavaScript file
Parameters:
-
url
StringThe target url of the script to be loaded
_onLoad
()
private
Fires when all classes ever required are loaded and defined
_parseClassName
-
className
Parses given class name and returns detailed information
Parameters:
-
className
StringThe name of the class
Returns:
_parseMeta
-
meta
Normalize meta data
Parameters:
-
meta
String | ObjectA class meta data object or name
Returns:
_processLoadedClass
-
className
Process delayed defines after dependencies are resolved
Parameters:
-
className
StringThe name of the class
_ready
()
private
Fires when all classes ever required are loaded and defined and the document is ready
_requireClass
-
className
Loads the related script file of the given class name
Parameters:
-
className
String
apply
-
obj
-
props
Apply properties to an object/class
Parameters:
-
obj
ObjectThe object witch the properties should be applied to
-
props
ObjectA JSON property structure
arrayUnique
-
data
Removes duplicate values from an array
Takes an input array and returns a new array without duplicate values.
Parameters:
-
data
ArrayThe input array
Returns:
clone
-
value
Clone variable
Returns a deep clone of given variable.
Parameters:
-
value
AnyThe variable to clone
create
-
name
Creates a class instance
All arguments after 'name' are passed to the init method of the class.
Parameters:
-
name
StringThe name of the class
Returns:
define
-
name
-
body
-
callback
Defines a new class
// Class definition without meta object
zerk.define('myNamespace.myClass',{
// ...
});
// Class definition with meta object
zerk.define({
name: 'myNamespace.myClass',
extend: 'myNamespace.myParentClass'
require: [
'myNamespace.myParentClass'
]
},{
// ...
});
Parameters:
-
name
String | ObjectThe name of the class or a meta object
-
body
ObjectThe body of the class
-
callback
FunctionCallback function that fires when the class definition is done
error
-
message
Raise error
The message can be specified as object with custom data:
zerk.error({
message: 'Log message',
customData: 'Debug me'
})
Parameters:
-
message
String | ObjectError message
exit
()
Halt execution
Throws an exception to halt the execution. Used for debbuging purposes.
inArray
-
needle
-
haystack
Checks if a value exists in an array
Searches haystack for needle using.
Parameters:
-
needle
StringThe searched value
-
haystack
ArrayThe array
Returns:
-
value
Returns true if the given variable is a string.
Parameters:
-
value
Object
Returns:
init
-
config
The main bootstrap method
Parameters:
-
config
ObjectConfiguration object
isArray
-
value
Returns true if the given variable is an array.
Link to the native "Array.isArray" method is possible.
Parameters:
-
value
Object
Returns:
isBoolean
-
value
Returns true if the given variable is boolean.
Parameters:
-
value
Object
Returns:
isDate
-
value
Returns true if the given variable is a date.
Parameters:
-
value
Object
Returns:
isDefined
-
value
Returns true if the given variable is not undefined.
Parameters:
-
value
Object
Returns:
isEmpty
-
value
Returns true if the given variable is empty.
Empty means:
Null
Undefined
Empty array
Empty string
Parameters:
-
value
Object
Returns:
isFunction
-
value
Returns true if the given variable is a function.
Parameters:
-
value
Object
Returns:
isNumber
-
value
Returns true if the given variable is a number.
Parameters:
-
value
Object
Returns:
isNumeric
-
value
Returns true if the given variable contains a numeric value.
Parameters:
-
value
Object
Returns:
isObject
-
value
Returns true if the given variable is an object.
Parameters:
-
value
Object
Returns:
isPrimitiveType
-
value
Returns true if the given variable a primitive type.
Primitive types are boolean, number and string.
Parameters:
-
value
Object
Returns:
log
-
message
Log message
The message can be specified as object with additional options:
zerk.log({
message: 'Log message',
group: 'Custom Group',
severity: 2
})
Parameters:
-
message
String | ObjectLog message
objectCount
-
data
Returns the count of the members of given object
Parameters:
-
data
ObjectThe input object
Returns:
objectKeys
-
data
Returns the names of the object members
Returns the names of the object members in an array.
Parameters:
-
data
ObjectThe input object
Returns:
objectValues
-
data
Return all the values of an object
Returns all the values from the input object in an array.
Parameters:
-
data
ObjectThe input object
Returns:
parent
-
name
Method for inheritance like parent class calls
Use this with the apply method to inject the local scope.
zerk.parent('myClass').myMethod.apply(
this,
arguments
);
Parameters:
-
name
StringThe name of the class
Returns:
typeOf
-
value
Returns the type of the given variable as string.
Possible values are:
"undefined"
"null"
"string"
"number"
"boolean"
"date"
"function"
"object"
"array"
"regexp"
"element"
Parameters:
-
value
Mixed
Returns:
warn
-
message
Warn message
The message can be specified as object with additional options:
zerk.warn({
message: 'Log message',
group: 'Custom Group'
})
Parameters:
-
message
String | ObjectWarn message
Properties
_classMap
Object
private
Class name to instance map
_classState
Object
private
Load state of classes
_config
Object
private
The game engine configuration
_delayedDefine
Object
private
Defines that got delayed by requires
_parentClassMap
Object
private
Class name to parent class map