English 中文(简体)
如果我改变变数的价值,它是否会在出口时更新?
原标题:If I change a value of a variable, will it update in a file that exported it?
  • 时间:2023-10-16 19:34:27
  •  标签:
  • node.js

请允许我说,我们有文件main.js,其代码如下:

var count = 0
function increase(){
    count = count + 1
}
export default count

当一个纽扣吨时,请打电话到<代码>increase()。

现在,如果我们从不同档案中进口变量,请说<编码>index.js。 之后,我们向纽特施加压力。 <代码>index.js更新? 如果没有,如何这样做?

问题回答

现在,如果我们从不同档案中进口变数,就请说指数。 之后,我们向纽特施加压力。 指数价值是否更新? 如果没有,如何这样做?

无。 当你进口像数件这样的原始价值时,你在进口时重新获得价值,然后将这一价值作为你新变数的复印件(无论你进口到该变量)。 它不再与原始档案中的进口变量有任何关系。

进口/出口更新物品的通常方式是出口具有财产的物体。 各种物体(如不动产)均通过复制同一物体的参考资料予以分配和进口。

const obj = { count: 0 };
function increase(){
    obj.count++;
}
export obj;

Then, you can import that object from another file and the count property in that object will reflect any changes made in either file because you will both have pointers to the exact same object and thus be accessing the same property in that object.





相关问题
How to make Sequelize use singular table names

I have an model called User but Sequelize looks for the table USERS whenever I am trying to save in the DB. Does anyone know how to set Sequelize to use singular table names? Thanks.

What is Node.js? [closed]

I don t fully get what Node.js is all about. Maybe it s because I am mainly a web based business application developer. What is it and what is the use of it? My understanding so far is that: The ...

Clientside going serverside with node.js

I`ve been looking for a serverside language for some time, and python got my attention somewhat. But as I already know and love javascript, I now want learn to code on the server with js and node.js. ...

Can I use jQuery with Node.js?

Is it possible to use jQuery selectors/DOM manipulation on the server-side using Node.js?

How do I escape a string for a shell command in node?

In nodejs, the only way to execute external commands is via sys.exec(cmd). I d like to call an external command and give it data via stdin. In nodejs there does yet not appear to be a way to open a ...

热门标签