Use module.exports instead of exports. exports is an alias to 
module.exports.But if you do this:
module.exports = { a: 'a', b: 'b" }; 

Then it breaks the link and exports will no longer work.
As Dave mentioned JavaScript is dynamically typed. If you want to be sure about 
the types in JavaScript then there's a couple approaches.
You could use TypeScript, which is a Microsoft language that gives you classes, 
types, etc and then transpiles down to JavaScript. 
You can also do things like:function my_function(createdOn) {   if (!(createdOn 
instanceof Date)) throw 'Bad';
}
To check the arguments as they come in when needed.

-Chris Grimeshalistechnology.com

From: [email protected]
To: [email protected]
Date: Wed, 24 Feb 2016 15:40:06 +0000
Subject: Re: [MarkLogic Dev General] Javascript coding help on ML 8








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, @dmcassel

Technical Community Manager
MarkLogic Corporation


http://developer.marklogic.com/













From: <[email protected]> on behalf of shruti kapoor 
<[email protected]>

Reply-To: MarkLogic Developer Discussion <[email protected]>

Date: Wednesday, February 24, 2016 at 5:52 AM

To: MarkLogic Developer Discussion <[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                         
                  
_______________________________________________
General mailing list
[email protected]
Manage your subscription at: 
http://developer.marklogic.com/mailman/listinfo/general

Reply via email to