Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

pointer to variable in JavaScript

Tags:

javascript

dom

Is there any way to create\return a pointer to variable in JavaScript ?
like, in PHP :

function func() {
    .....
    return &$result;
}

I have a JS function like:

function(...) {
    x=document.getElements..... //x is HTML tag
    if (x.localName=='input') return x.value //String variable
    else if (x.localName=='textarea') return x.innerHTML //String variable
}

Using this function, I can get a copy of the data from x, but not to change the source.
I want possibility to change it too.

Thanks

like image 372
Dani-Br Avatar asked May 19 '26 22:05

Dani-Br


1 Answers

No, you can't return a pointer to a string. In Javascript Objects are assigned and passed by reference automatically, and primitives are copied. So if you return x; then you can modify x.innerHTML, but if you return x.innerHTML the string will be copied.

like image 164
Paul Avatar answered May 22 '26 11:05

Paul