首页 > 解决方案 > Javascript对象和变量之间的关系

问题描述

在 javascript 中,对象被视为变量(至少据我所知)。

前任:

var myCar = new Object();
myCar.make = 'Ford';
myCar.model = 'Mustang';
myCar.year = 1969;

我不明白这背后的逻辑。即使在像 c++ 这样的语言中也是如此(即 C++ 对象可以被视为变量)吗?

标签: javascriptobjectoopvariables

解决方案


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.


推荐阅读