Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

what is the 'use' keyword in javascript?

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"

like image 737
shed_fortest Avatar asked Dec 21 '16 17:12

shed_fortest


People also ask

What is JavaScript this keyword example?

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.

Is type a keyword in JavaScript?

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.

What is use strict in JavaScript?

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.


Video Answer


2 Answers

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

like image 109
peteb Avatar answered Sep 21 '22 05:09

peteb


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.

like image 32
Romain Lanz Avatar answered Sep 19 '22 05:09

Romain Lanz