Najova

DocsGuides

Modules

Split a big project into files. Any .naja file can share its functions with the others.

Here a project has two files. prices.naja makes two functions:

$-- prices.naja
$private[taxRate]
$function[taxRate]
  $return[0.1]
$endfunction
$function[withTax;price]
  $return[$round[$get[price] * (1 + $taxRate);2]]
$endfunction

The main script loads it with $use and calls its functions by the module's name:

shop.naja
$use[prices]
$print[With tax: $call[prices.withTax;20]]
najova run shop.naja
With tax: 22

$private keeps a function inside its own file: shop.naja can use withTax but not taxRate.

Where Najova looks

$use[prices] looks for prices.naja (or .naj) beside the script first, then in a modules folder beside it. A file is loaded once, however many scripts use it.