javascript - Javascript对象和变量之间的关系
问题描述
在 javascript 中,对象被视为变量(至少据我所知)。
前任:
var myCar = new Object();
myCar.make = 'Ford';
myCar.model = 'Mustang';
myCar.year = 1969;
我不明白这背后的逻辑。即使在像 c++ 这样的语言中也是如此(即 C++ 对象可以被视为变量)吗?
解决方案
Technically the myCar
that you created is a variable which stores the instance of the object that you created using new Object()
.
Variables are like a box where in you can store specific data and access it along your code.
So variables can come in many shape or form depending on what data you put on it. It can come as a string, objects, array, number or boolean.. It does not always have to be an object.
推荐阅读
- c# - C# - 没有参数名称的 Uribuilder
- amazon-web-services - 控制 AWS Sagemaker 成本
- python - 如何根据出现在该词之前的条件词替换熊猫字符串中的下一个词
- javascript - 如何使用 textinput 将多个项目添加到平面列表?
- macos - 使用 brew 在 Mac 上安装 rabbitmq 时出错
- react-redux - const logger = reduxLogger.createLogger(); ^ 类型错误:reduxLogger.createLogger 不是函数
- javascript - 将字符串转换为数组格式的java脚本
- python-3.x - 根据优先级修改数据框
- java - 如何在swift的“for循环”中改变i变量
- git - 在 MacOS Catalina 上使用 zsh git 提示缺少分支名称