首页 > 解决方案 > 新的 Javascript Const 关键字使用

问题描述

我正在尝试学习 JavaScript 代码,但以下是一些陈述。我无法理解。

const node = active[data]; // Is the code assiging a value to the node  
const subviews = view.subviews(); // What does view.subviews() means 
const view = node.instance;  // What does node.instance means
this.className = view.$className; // What does $ sign means
this._enabled = null;  // Why enabled was used since there was no object declared wit name _enabled.

有人可以解释为什么使用上述语句吗?

标签: javascriptclassconstants

解决方案


这些示例中的大多数最有可能用于混叠目的。

例如。

const node = active[data];
node.value = 7;
node.qty = 8;

将与

active[data].value = 7;
active[data].qty = 8;

附言。价值和数量只是我编造的属性。

IOW:它省去了active[data]不断打字的麻烦。

另一种选择是使用with,但这是不受欢迎的,而且容易出错。


推荐阅读