Loading TOC...

xdmp.function

xdmp.function(
   $function as xs.QName?,
   [$module-path as String?]
) as function

Summary

Returns a function value as an xdmp.function type. You can return an xdmp.function from an expression or a function. You can execute the function referred to by an xdmp.function by passing the xdmp.function value to xdmp.apply. If the module-path ends with a file extension matching the ones configured for application/vnd.marklogic-javascript in your MarkLogic Mimetypes configuration, and the function's namespace URI is empty, the module is considered to be JavaScript. In this case, the function parameter can be empty.

Parameters
$function The function QName, which includes its local name and namespace. If the function is not found in the current query context or in the module specified in the second parameter, then an exception is thrown when the function is used with xdmp.apply.
$module-path The optional path to the module where the function specified in the first parameter is defined. If the module-path is not supplied, the function QName must be in-scope in the query context. If the empty sequence is supplied, the function behaves as if the parameter is not supplied (that is, it uses the in-scope query context).

Example

xdmp.function(xs.QName("fn:empty"))

Example

var f = xdmp.function(xs.QName("fn:concat"));
xdmp.apply(f, "hello", " world");

=> hello world

Example

// Given square.sjs in the modules database as the following:

module.exports = function(width) {
  return {
    area: function() {
      return width * width;
    },
    set: function(_width) {
      width = _width;
    }
  };
}
// then you can run the following
var mySquare = fn.head(xdmp.apply(xdmp.function(null,"square.sjs"),4));
xdmp.apply(mySquare.set, 3);
xdmp.apply(mySquare.area)

=> 9

Comments

    Powered by MarkLogic Server 7.0-4.1 and rundmc | Terms of Use | Privacy Policy