API Docs for: 0.1.0
Show:

zerk Class

Defined in: src/zerk/zerk.js:29
Module: zerk

Zerk Object

The Zerk main object and namespace

Methods

_classLoaded

(
  • className
)
Boolean private

Checks if a class is loaded and defined already

Parameters:

  • className String

    The name of the class

Returns:

Boolean: Returns true if the class is loaded and defined already

_classLoading

(
  • className
)
Boolean private

Checks if a class is loading already

Parameters:

  • className String

    The name of the class

Returns:

Boolean: Returns true if the class is currently loading

_createObject

(
  • parent
)
Object private

Creates an object from parent object definition

This is an implementation of Douglas Crockfords prototypal inheritance in JavaScript.

http://javascript.crockford.com/prototypal.html

Parameters:

  • parent Object

Returns:

Object: The created object

_defineClass

(
  • meta
  • body
  • callback
)
Object private async

Defines a class

Parameters:

  • meta Object

    Class meta object

  • body Object

    Class body

  • callback Function

    Callback function that fires after the class was defined

Returns:

Object: Class definition

_delayDefine

(
  • meta
  • body
  • callback
  • waitFor
)
Object private async

Creates a delayed define entry and returns its handle

Parameters:

  • meta Object

    Class meta object

  • body Object

    Class body

  • callback Function

    Callback function

  • waitFor Array

Returns:

Object: The handle for the delayed define

_getClassURL

(
  • className
)
String private

Returns the url for given class name

Parameters:

  • className String

    The name of the class

Returns:

String: Class name in object key notation

_initErrorHandler

() private

Initializes the error handler

_loadScript

(
  • url
)
private

Loads a JavaScript file

Parameters:

  • url String

    The target url of the script to be loaded

_onLoad

() private

Fires when all classes ever required are loaded and defined

_parseClassName

(
  • className
)
Object private

Parses given class name and returns detailed information

Parameters:

  • className String

    The name of the class

Returns:

Object: An object containing namespace information

_parseMeta

(
  • meta
)
Object private

Normalize meta data

Parameters:

  • meta String | Object

    A class meta data object or name

Returns:

Object: The parsed meta data object

_processLoadedClass

(
  • className
)
private

Process delayed defines after dependencies are resolved

Parameters:

  • className String

    The name of the class

_ready

() private

Fires when all classes ever required are loaded and defined and the document is ready

_requireClass

(
  • className
)
private

Loads the related script file of the given class name

Parameters:

  • className String

apply

(
  • obj
  • props
)

Apply properties to an object/class

Parameters:

  • obj Object

    The object witch the properties should be applied to

  • props Object

    A JSON property structure

arrayUnique

(
  • data
)
Array

Removes duplicate values from an array

Takes an input array and returns a new array without duplicate values.

Parameters:

  • data Array

    The input array

Returns:

Array: Returns the filtered array

clone

(
  • value
)

Clone variable

Returns a deep clone of given variable.

Parameters:

  • value Any

    The variable to clone

create

(
  • name
)
Object

Creates a class instance

All arguments after 'name' are passed to the init method of the class.

Parameters:

  • name String

    The name of the class

Returns:

Object: Class instance

define

(
  • name
  • body
  • callback
)
async

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 | Object

    The name of the class or a meta object

  • body Object

    The body of the class

  • callback Function

    Callback 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 | Object

    Error message

exit

()

Halt execution

Throws an exception to halt the execution. Used for debbuging purposes.

inArray

(
  • needle
  • haystack
)
Boolean

Checks if a value exists in an array

Searches haystack for needle using.

Parameters:

  • needle String

    The searched value

  • haystack Array

    The array

Returns:

Boolean: True when needle in contained in haystack

(
  • value
)
Boolean

Returns true if the given variable is a string.

Parameters:

  • value Object

Returns:

Boolean:

init

(
  • config
)

Defined in src/zerk/zerk.js:85

The main bootstrap method

Parameters:

  • config Object

    Configuration object

isArray

(
  • value
)
Boolean

Returns true if the given variable is an array.

Link to the native "Array.isArray" method is possible.

Parameters:

  • value Object

Returns:

Boolean:

isBoolean

(
  • value
)
Boolean

Returns true if the given variable is boolean.

Parameters:

  • value Object

Returns:

Boolean:

isDate

(
  • value
)
Boolean

Returns true if the given variable is a date.

Parameters:

  • value Object

Returns:

Boolean:

isDefined

(
  • value
)
Boolean

Returns true if the given variable is not undefined.

Parameters:

  • value Object

Returns:

Boolean:

isEmpty

(
  • value
)
Boolean

Returns true if the given variable is empty.

Empty means:

Null
Undefined
Empty array
Empty string

Parameters:

  • value Object

Returns:

Boolean:

isFunction

(
  • value
)
Boolean

Returns true if the given variable is a function.

Parameters:

  • value Object

Returns:

Boolean:

isNumber

(
  • value
)
Boolean

Returns true if the given variable is a number.

Parameters:

  • value Object

Returns:

Boolean:

isNumeric

(
  • value
)
Boolean

Returns true if the given variable contains a numeric value.

Parameters:

  • value Object

Returns:

Boolean:

isObject

(
  • value
)
Boolean

Returns true if the given variable is an object.

Parameters:

  • value Object

Returns:

Boolean:

isPrimitiveType

(
  • value
)
Boolean

Returns true if the given variable a primitive type.

Primitive types are boolean, number and string.

Parameters:

  • value Object

Returns:

Boolean:

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 | Object

    Log message

objectCount

(
  • data
)
Integer

Returns the count of the members of given object

Parameters:

  • data Object

    The input object

Returns:

Integer: Member count

objectKeys

(
  • data
)
Array

Returns the names of the object members

Returns the names of the object members in an array.

Parameters:

  • data Object

    The input object

Returns:

Array: Returns the names of the object members as array

objectValues

(
  • data
)
Array

Return all the values of an object

Returns all the values from the input object in an array.

Parameters:

  • data Object

    The input object

Returns:

Array: Returns the values of the object as array

parent

(
  • name
)
Object

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 String

    The name of the class

Returns:

Object: The parent class

typeOf

(
  • value
)
String

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:

String:

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 | Object

    Warn message

Properties

_classMap

Object private

Defined in src/zerk/zerk.js:58

Class name to instance map

_classState

Object private

Defined in src/zerk/zerk.js:49

Load state of classes

_config

Object private

Defined in src/zerk/zerk.js:40

The game engine configuration

_delayedDefine

Object private

Defined in src/zerk/zerk.js:76

Defines that got delayed by requires

_parentClassMap

Object private

Defined in src/zerk/zerk.js:67

Class name to parent class map