For making modules, there's a description of this at the Global-Object.require 
page (http://docs.marklogic.com/Global-Object.require). Example:


 lib.sjs:
  var PI = Math.PI;
  exports.area = function area(r) {
    return PI * r * r;
  };


  Test.js:
  var circle = require("lib");
  circle.area(2);

Key point is to set up the exports global with references to functions you want 
to export. You can then access these by requiring them in another file.

For specifying datatypes in function arguments and returns, the JavaScript 
language doesn't support this.

For functions where this is particularly important, consider leaving that code 
in XQuery and using it in JavaScript. You can call XQuery from JavaScript and 
JavaScript from XQuery. 
http://developer.marklogic.com/learn/sjs/working-together

--
Dave Cassel<http://davidcassel.net>, @dmcassel<https://twitter.com/dmcassel>
Technical Community Manager
MarkLogic Corporation<http://www.marklogic.com/>
http://developer.marklogic.com/


From: 
<[email protected]<mailto:[email protected]>>
 on behalf of shruti kapoor 
<[email protected]<mailto:[email protected]>>
Reply-To: MarkLogic Developer Discussion 
<[email protected]<mailto:[email protected]>>
Date: Wednesday, February 24, 2016 at 5:52 AM
To: MarkLogic Developer Discussion 
<[email protected]<mailto:[email protected]>>
Subject: [MarkLogic Dev General] Javascript coding help on ML 8


Hi all

We have upgraded from ML 7 to 8 and want to replace the existing xqy code with 
javascript. But I am facing the following problems :

1) How to make modules in JS

2) Specifying datatype in function arguments and return type.

Any help is much appreciated!

Thanks
Shruti Kapoor
_______________________________________________
General mailing list
[email protected]
Manage your subscription at: 
http://developer.marklogic.com/mailman/listinfo/general

Reply via email to