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"
In JavaScript, the this keyword refers to an object. Which object depends on how this is being invoked (used or called). The this keyword refers to different objects depending on how it is used: In an object method, this refers to the object.
typeof is a JavaScript keyword that will return the type of a variable when you call it. You can use this to validate function parameters or check if variables are defined. There are other uses as well. The typeof operator is useful because it is an easy way to check the type of a variable in your code.
The "use strict" Directive It is not a statement, but a literal expression, ignored by earlier versions of JavaScript. The purpose of "use strict" is to indicate that the code should be executed in "strict mode". With strict mode, you can not, for example, use undeclared variables.
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
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With