[英]Variables when requiring a NPM package
I see a lot of NPM packages using let
or var
.我看到很多 NPM 包使用
let
或var
。
eg: var firebase = require('firebase');
例如:
var firebase = require('firebase');
My inner OCD suggest these should always be defined as const
variables.我内心的强迫症建议这些应该始终定义为
const
变量。
Can anyone give a final answer on how these should be declared?任何人都可以就如何声明这些内容给出最终答案吗?
It's a good practice to create as const
anything that you are not going to change the value.将不会更改值的任何内容创建为
const
是一个很好的做法。 Since you're not going to change firebase object, you should import it to a const
.由于您不会更改 firebase object,因此您应该将其导入
const
。
Node.js uses commonJS module. Node.js 使用 commonJS 模块。
let
and const
is ES6 javascript syntax for declaring variables. let
和const
是 ES6 javascript 用于声明变量的语法。
So requiring a module is usually declared with const
所以需要一个模块通常用
const
声明
const express = require('express')
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.