How can I obtain the names of the variables to require?


Warning: count(): Parameter must be an array or an object that implements Countable in /home/styllloz/public_html/qa-theme/donut-theme/qa-donut-layer.php on line 274
0 like 0 dislike
22 views
Unfamiliar with Node.js however use require in the browser with browserify.

The question is:
Was wondering why the variables which is given module must have a title and where you can find out the name?

For example for jQuery:
const $ = require('jquery');
Why $?
(Note: this is not a question but an example. No need to answer it. Question is above.)
by | 22 views

3 Answers

0 like 0 dislike
Was wondering why the variables which is assigned to the module must have a title and where you can find out the name?

It's not true. You can use any names, just there is a tradition (habit) and compatibility with legacy code.

Specifically, your example about jQuery — it's a tradition and compatibility. There is a lot of code, plugins, etc. which are written with a calculation that the variable $ lies jQuery. Nobody prevents you to write this:
const jq = require('jquery'); ... jq('.selector').hide(); // etc.
by
0 like 0 dislike
well, it's logical, it's more convenient to refer to these variables is the same as to ask why in the for loop uses the variable i. Because it's standard, and as usual, you can use any other, but to read your code will be much harder
by
0 like 0 dislike
Don't have to, you can call whatever you like. For jQuery $ -- historically and _ for underscore.

However, common sense dictates that it would be better to call these variables according to the libraries that they reference. So we need to do: var angular = require("backbonejs");. So, too, is not:
var foo = require("./bar"); var bar = require("./foo");
.
by

Related questions

0 like 0 dislike
1 answer
0 like 0 dislike
1 answer
0 like 0 dislike
1 answer
0 like 0 dislike
1 answer
110,608 questions
257,187 answers
0 comments
40,796 users