【问题标题】:Organizing JavaScript Variables in VsCode?在 VsCode 中组织 JavaScript 变量?
【发布时间】:2022-01-09 09:48:34
【问题描述】:

寻找一种在 vsCode 中组织变量的方法。类似于在工作区中折叠函数的方式,我希望能够折叠一长串变量...

var x = 1 
var y = 2
var z = 3
var w = 4
var v = 5
//etc.

【问题讨论】:

标签: javascript variables visual-studio-code code-organization


【解决方案1】:

我能想到 2 个hacks

  1. 代码块important!注意变量范围)

  2. 对象字面量

代码块示例:

{
    const x = 10;
    const y = 20;
}

对象字面量示例:

const variablesNamespace = {
    x: 10,
    y: 10
}

console.log(variablesNamespace.x) // output 10

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-01-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-05-05
    相关资源
    最近更新 更多