<?xml version="1.0" encoding="UTF-8"?><api:function-page xml:base="/apidoc/8.0/xdmp.apply.xml" generated="2015-10-07T16:36:00.016766-07:00" mode="javascript" xmlns:api="http://marklogic.com/rundmc/api"><api:function-name>xdmp.apply</api:function-name><api:suggest>xdmp.apply</api:suggest><api:suggest>xdmp</api:suggest><api:suggest>apply</api:suggest><api:function-link mode="xquery" fullname="xdmp:apply">/apidoc/8.0/xdmp:apply.xml</api:function-link><api:function mode="javascript" name="apply" type="builtin" lib="xdmp" category="Extension" subcategory="Function Values" hidden="false" bucket="MarkLogic Built-In Functions" prefix="xdmp" namespace="http://marklogic.com/xdmp" fullname="xdmp.apply"><api:summary>
  Applies an <code xmlns="http://www.w3.org/1999/xhtml">xdmp:function</code> with the given parameters.
</api:summary><api:params><api:param name="function" type="xdmp:function"><api:param-description>
    The xdmp:function value to be applied.
  </api:param-description><api:param-name>function</api:param-name><api:param-type>function</api:param-type></api:param><api:param name="params-1-to-N" type="item()*" optional="true"><api:param-description>
    The parameters to pass into the specified function value.  Specify one
    parameter for each parameter that the specified function takes, with the
    first parameter corresponding to the first parameter in the specified
    function's signature, the second parameter corresponding to the second,
    and so on.  Omit this parameter if the specified function takes no
    parameters.
  </api:param-description><api:param-name>params-1-to-N</api:param-name><api:param-type>ValueIterator</api:param-type></api:param></api:params><api:return>ValueIterator</api:return><api:example class="javascript"><pre xml:space="preserve" xmlns="http://www.w3.org/1999/xhtml">
var f = xdmp.function(xs.QName("fn:empty"));
xdmp.apply(f, []);

  =&gt; true
</pre></api:example><api:example class="javascript"><pre xml:space="preserve" xmlns="http://www.w3.org/1999/xhtml">
var f = xdmp.function(xs.QName("fn:concat"));
xdmp.apply(f, "hello", " world");

=&gt; hello world
</pre></api:example><api:example class="javascript"><pre xml:space="preserve" xmlns="http://www.w3.org/1999/xhtml">
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;
    }
  };
}

var mySquare = xdmp.apply(xdmp.function(null,"square.sjs"),4);
xdmp.apply(mySquare.set, 3);
xdmp.apply(mySquare.area)

=&gt; 9
</pre></api:example></api:function></api:function-page>