Jump to navigation

Class: funcObj

Numbas.jme.funcObj

new funcObj(name, intype, outcons, fn, options)

A JME function. Capable of confirming that it can be evaluated on a given list of arguments, and returning the result of its evaluation on a list of arguments inside a given scope.

Parameters:
Name Type Description
name string
intype Array.<(function()|string)>

A list of data type constructors for the function's parameters' types. Use the string '?' to match any type. Or, give the type's name with a '*' in front to match any number of that type. If null, then options.typecheck is used.

outcons function

The constructor for the output value of the function.

fn Numbas.jme.evaluate_fn

JavaScript code which evaluates the function.

options Numbas.jme.funcObj_options
Source:

Members

(static) description :string

A description of what the function does.

Type:
Source:

(static) fn :function

Javascript function for the body of this function.

Type:
Source:

(static) id :number

Globally unique ID of this function object.

Type:
Source:

(static) intype :function

Check the given list of arguments against this function's calling signature.

Type:
Source:

(static) name :string

The function's name.

Type:
Source:

(static) outtype :function|string

The return type of this function. Either a Numbas.jme.token constructor function, or the string '?', meaning unknown type.

Type:
Source:

(static) random :boolean

Does this function behave randomly?

Type:
Source:

Methods

(static) evaluate(args, scope) → {Numbas.jme.token}

Evaluate this function on the given arguments, in the given scope.

Parameters:
Name Type Description
args Array.<Numbas.jme.token>
scope Numbas.jme.Scope
Returns:
Type Description
Numbas.jme.token
Source:

(static) typecheck(variables) → {boolean}

Can this function be called with the given list of arguments?

Parameters:
Name Type Description
variables Array.<Numbas.jme.token>
Returns:
Type Description
boolean
Source: