Does a Javascript function return objects by reference or value by default?

后端 未结 5 921
粉色の甜心
粉色の甜心 2020-12-30 23:24

I have an object defined outside the function, in a global scope. This object is not passed into the function as an argument, but the function does modify it and return the

5条回答
  •  星月不相逢
    2020-12-30 23:50

    What I wanted to know is, if the function returns a copy of the object, or the original global object?

    Effectively, you only ever deal with references to objects in JavaScript. Even var foo = {} just assigns a reference to a new object to foo.

提交回复
热议问题