[英]How to reuse constants in the same config.js file
I am trying to create a config.js file, which should contains the constants for the other js files that I have. 我正在尝试创建config.js文件,该文件应包含我拥有的其他js文件的常量。 I could not find any other information about that if it is possible to "reuse" the constants in the same config file.
如果可以在同一配置文件中“重用”常量,则我找不到任何其他信息。
For example: 例如:
const Config = { ROWS: 10, COLUMNS: ROWS, }; const Config = {ROWS:10,COLUMNS:ROWS,};
const tableWidth = 10;
const config = {
ROWS: tableWidth,
COLUMNS: tableWidth,
};
But instead of doing it this way, I would find a better name for the constant and use it anywhere it needs to be used, rather than setting two constants to the same value. 但是,与其以这种方式进行操作,不如为常数找到一个更好的名称,并在需要使用的任何地方使用它,而不是将两个常数设置为相同的值。
const config = {
TABLE_DIMENSION: 10,
};
Seems like you want to reuse a property during object definition which unfortunately is not possible. 似乎您想在对象定义期间重用属性,这是不可能的。 Although, you can reuse them like this.
虽然,您可以像这样重复使用它们。
const Config = { ROWS: 10 }
Config.COLUMNS = Config.ROWS
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.