function.definition

Learn: User-defined functions (UDFs)

function.definition is a deprecated. Use Function.byName() instead.

To look up a definition using an alias, use FQL.Schema.defForIdentifier().

Get or update a user-defined function (UDF)'s definition, represented as a Function document.

Signature

<Function>.definition: FunctionDef

Description

The definition property is a user-defined functions (UDFs)'s schema, represented as a Function document with the FunctionDef type. The document is an FQL version of the FSL function schema.

You access the property using an existing UDF’s name.

Definition properties

You can use dot or bracket notation to access specific fields in the definition. See Access definition properties.

Definition methods

The definition property supports function instance methods.

Return value

Type Description

FunctionDef

Definition for the UDF, represented as a Function document.

Examples

Basic example

// Get the definition for
// the `getOrCreateCart()` UDF.
getOrCreateCart.definition
{
  name: "getOrCreateCart",
  coll: Function,
  ts: Time("2099-10-03T20:30:59.360Z"),
  body: <<-END
    (id) => {
      let customer = Customer.byId(id)!
      if (customer!.cart == null) {
        Order.create({
          status: "cart",
          customer: Customer.byId(id),
          createdAt: Time.now(),
          payment: {
          }
        })
      } else {
        customer!.cart
      }
    }
  END
}

Access definition properties

Use dot or bracket notation to access specific fields in the definition:

// Access the `body` field for
// the `getOrCreateCart()` UDF.
getOrCreateCart.definition.body
// Only returns the `body` field.
<<-END
  (id) => {
    let customer = Customer.byId(id)!
    if (customer!.cart == null) {
      Order.create({
        status: "cart",
        customer: Customer.byId(id),
        createdAt: Time.now(),
        payment: {
        }
      })
    } else {
      customer!.cart
    }
  }
END
\