$k. Script

An element that can be added to a folder

Constructor

new $k.Script(optionsopt)

Create a new script element

Parameters:
NameTypeAttributesDescription
optionsobject<optional>

Options object

Properties
NameTypeAttributesDescription
idstring<optional>

Registers the script with this ID

Since
  • 6.2
Throws:

Extends

Methods

callFunction(name, functionArguments) → {any}

Calls a function that is defined in the script

Parameters:
NameTypeDescription
namestring

The name of a function defined in the script

functionArgumentsArray.<any>

Array of arguments passed to the function

Since
  • 5.8.3
Throws:

If the script does not define a function with the given name

Type
UndeclaredFunctionError
Returns:

The return value of the evaluated function

Type: 
any

deregister()

Deregisters the element. The ID will be undefined afterwards. Equivalent to setId(undefined)

See
  • setId
Throws:

jsDocNoAdminRights

Type
$k.exception.AccessDenied

eval() → {any}

Evaluates the script. Equivalent to eval(source())

Since
  • 5.4.2
Returns:

The return value of the evaluated script

Type: 
any

id() → {string|undefined}

Returns the registered ID, or undefined if not registered.

Inherited From
Returns:
Type: 
string | undefined

module() → {object}

Returns the module exports of the script

Since
  • 5.4.2
Throws:

If this script is not registered

Type
$k.exception.RuntimeError
Returns:
Type: 
object

name() → {string}

Returns the name of the element

Since
  • 6.1.1
Returns:
Type: 
string

parentFolders() → {Array.<$k.Folder>}

Returns the folders that contain this element

Returns:
Type: 
Array.<$k.Folder>

register(replaceScriptReferencesopt) → {string}

Registers the element with a private ID, if it has no registered ID yet.

Parameters:
NameTypeAttributesDefaultDescription
replaceScriptReferencesboolean<optional>
false

True if ID references in scripts should be replaced. Only done when the old and the new ID is not undefined.

Since
  • 6.1.1
Throws:

jsDocNoAdminRights

Type
$k.exception.AccessDenied
Returns:

The registered ID

Type: 
string

registryType() → {string}

Returns the name of the registry that contains elements of this type

Returns:
Type: 
string

remove()

Deletes the element and removes it from all containing registries and folders

Throws:

setId(id, replaceScriptReferencesopt)

Registers the element with the given ID. If the element has already been registered, the current ID will be changed to the new ID.

Deprecated option: If the given ID is undefined or null, the element will be deregistered. Use deregister() instead

Parameters:
NameTypeAttributesDefaultDescription
idstring | null

The ID to set

replaceScriptReferencesboolean<optional>
false

True if ID references in scripts should be replaced. Only done when the old and the new ID is not undefined.

See
  • deregister
Throws:

jsDocNoAdminRights

Type
$k.exception.AccessDenied

setName()

Sets the name of the element

Since
  • 6.1.1
Throws:

jsDocNoAdminRights

Type
$k.exception.AccessDenied

setSource(source)

Sets the source code of the script

Parameters:
NameTypeDescription
sourcestring

The new query source

Since
  • 6.1.1
Throws:

source() → {string}

Returns the script source code

Since
  • 5.4.2
Throws:

If accessing the source is not allowed

Type
$k.exception.AccessDenied
Returns:
Type: 
string