All Questions
Tagged with pass-by-reference object
130 questions
0
votes
0
answers
63
views
What is the best way to pass an object by reference in JavaScript without modifying it
I studied that Javascript passes objects by 'pass by reference' to functions. When those objects are mutated/updated inside a function, then it affects the original object. This is clear!
let obj = {
...
0
votes
0
answers
22
views
Pushing object into Array of Arrays retains pointer to original object [duplicate]
I was wondering if anyone could help provide context on this one.
With the below example:
const finalArray: any[][] = []
const accumulatedArray: any[] = []
const ids = ['1','2']
for (const id of ids) ...
0
votes
0
answers
38
views
Javascript object copy [duplicate]
I wanted to understand why when I make a copy of an object and reassign the "nestedObject" property from the obj2 (copy) is only modified in the obj2 (copy) and not in the original object. ...
0
votes
1
answer
102
views
typescript transpiling error with find array method
I have this code in Typescript
/**
* Team information
*/
export class Team {
constructor( public name: string ) {}
}
/**
* Half side of each match, with team and score of the team
*/
...
0
votes
0
answers
49
views
I am not able to understand why parent reference variable value of all recursive calls changes as soon as parent=n is done?
Node parent;
private int size;
public void addNodes() {
if (size == 0) {
Node n = new Node(sc.nextInt());
parent = n;
root = n;
size++;
...
2
votes
1
answer
446
views
How do you pass in another object of the same type as a method parameter in python?
I am creating a class in python to represent a three-dimensional point (I know there are libraries to do this, it's more of an exercise in classes). One type of method I wish to have is one which can ...
1
vote
1
answer
21
views
In javascript, how do I make a class take an object's properties by reference?
I don't want to use the extends keyword because I am making a browser extension and I only have access to the instance, not class definition. so I am wondering if it is possible to assign the props of ...
0
votes
0
answers
23
views
C++ assigning structs/objects by reference in order to avoid long lines and improve readability [duplicate]
Problem
Basically I am just looking for a text replacement for a object which i have to access through a nested structure so I don't have this long lines.
Camera cam = clients_manager....
0
votes
2
answers
772
views
Replace values in array of object with values from another array in JavaScript
This should be a small task, but could not figure it out.
I've an array of objects named 'A'
A = [{x:a,y:10},{x:b,y:5},{x:c,y:50}]
and an array named 'B'
B = ['2022-06-15','2022-06-16','2022-06-17']
...
-1
votes
2
answers
36
views
Affects of object assignment within a function on global object values
Can someone please help explain why the value property of obj1 remains the same while in obj2 it changes? I know it has to do with obj1 being assigned to obj2 within the change function but I'm not ...
0
votes
1
answer
333
views
Is there a way to initialize object, call its method, then pass it as function argument, in just the function call scope?
Is there a way to initialize an object, call a few of its method (it is not possible to just construct the object to be in the needed state), then pass it as an argument to a function, and possibly ...
-3
votes
1
answer
685
views
void *function() to call in main using the object of class in c++ [duplicate]
I want to call the void *function inside main using the object of the class
class SERVER{
public:
void *handle_client(void *arg){
...
}
};
int main(){
SERVER s1;
pthread_create(&...
0
votes
1
answer
682
views
Create Function to Copy Properties From One Object to Another
I am trying to create a function that will copy all properties from a source object and paste them to a destination object. I want to create a deep copy, so I am not using object.assign().
Here is my ...
-1
votes
3
answers
98
views
Java - Can I multiply referenced values?
If I have a class as follows, just to store a value:
public class RefTest{
private int value;
public void setValue(int value){
this.value = value;
}
public int getValue(){
...
0
votes
0
answers
23
views
Return a manipulated mutable Python object passed by reference [duplicate]
Is it good practice to return an object that is passed by reference and manipulated in a function?
Which of these two approaches is more pythonic? Not returning a manipulated object in place or to ...