Methods

A Method item inside a Schema declares a named operation on a governed type — its name, parameters, return type, and implementation. A Method is a kind of Property item, declared with itemtype="https://pagelove.org/Method" instead of .../Property.

A declared method is the thing a Method Element invokes during page composition: declaring the method is data modeling; calling <prefix:method-name> in a page is composition. This page documents the declaration; see Method Elements for invocation.

Declaration

A Method is a <li itemprop="property" itemscope itemtype="https://pagelove.org/Method"> in the Schema's property list:

<div hidden itemscope itemtype="https://pagelove.org/Schema">
  <meta itemprop="type" content="urn:Test">
  <ul>
    <li itemprop="property" itemscope itemtype="https://pagelove.org/Method">
      <meta itemprop="name" content="foo">
      <meta itemprop="returns" content="https://pagelove.org/Element">
      <div itemprop="implementation" itemscope itemtype="https://pagelove.org/Sessel">
        <script itemprop="source" type="text/sessel">
          new ul { new li { "foo" } }
        </script>
      </div>
    </li>
  </ul>
</div>

The schema is registered with the host's cache when the document containing it is PUT/POST'd.

Fields

Field itemprop Required Description
Name name yes The method name. Matches the local name in a Method Element's tag (foo in <t:foo>) and the property name in an in-VM call (obj.foo()).
Implementation implementation yes An item whose itemtype is https://pagelove.org/Sessel or https://pagelove.org/JavaScript/Module, with the method body in its source.
Return type returns no A type URL hint. https://pagelove.org/Element (or a subtype) marks the result as an HTML fragment.
Parameters parameter no Zero or more <li itemprop="parameter" itemscope itemtype="https://pagelove.org/Parameter"> items, each with a name and type, in declared order.
Static static no <meta itemprop="static" content="true"> declares a class-side method, installed on the constructor rather than the prototype and invoked with the constructor itself bound as self/this, rather than an instance.

Implementation languages

The implementation item's itemtype selects the language:

Both languages produce the same kinds of result; how a returned value updates a page is documented under Method Elements.

Parameters

Each parameter is a <li itemprop="parameter" itemscope itemtype="https://pagelove.org/Parameter"> with a name and a type:

<li itemprop="parameter" itemscope itemtype="https://pagelove.org/Parameter">
  <meta itemprop="name" content="title">
  <meta itemprop="type" content="https://schema.host/Text">
</li>

The declared parameter order is the order JavaScript implementations receive their positional arguments; Sessel implementations read each by name.

Overloading

Two methods on the same schema may share a name while declaring different parameters. A caller selects the overload whose declared parameters are all supplied. The most specific match — the overload whose full parameter set is present — wins.

doesNotUnderstand

A method named literally doesNotUnderstand is a catch-all: it handles any invocation whose name matches no declared method on the schema. It always receives messageName (the unrecognised name) and parameters, but the shape of parameters depends on how the invocation was dispatched during page composition — a list of { name, value } maps for an element-tag dispatch, or a list containing a single bare string for an attribute dispatch. A Sessel implementation reads messageName and parameters as named locals; a JavaScript implementation declares them as parameters (messageName, then parameters), positionally. The two dispatch forms and their respective parameters shapes are documented under Method Elements.

See also