what is the 'use' keyword in javascript?

11.1k views Asked by At

I am looking at this specific line of code to understand what it is or to find some documentation about it.

https://github.com/adonisjs/adonis-rally/blob/c7378d2c3984bffba1049f50e771318ea447107c/app/Model/Channel.js

const Lucid = use('Lucid')

I am trying to write a test in adonisjs using mocha and it gives me the following error "ReferenceError: use is not defined"

2

There are 2 answers

1
peteb On BEST ANSWER

The use() function is provided by adonis.js.

use(namespace/alias)

Fetch a binding using it’s namespace or alias.

The adonis-lucid package has an example of how to create a model that looks identical to the code that you've linked in your question. Creating a model docs

0
Romain Lanz On

To complete the answer. use() function is provided by the IoC Container of AdonisJs (adonis-fold).

This function will try to resolve a binding or a namespace defined in your Adonis configuration file and will then fallback to the default require() function to import a package if it didn't find anything.