1

Specifically, I want to create an HTML <input> element, and obtain a reference to its value property such that I can change its value through that reference:

var input = document.createElement('input');
var valueRef = &(input.value);
*valueRef = "Hello world!"

The syntax is obviously pseudo, I'm adding some C++ to illustrate my desire. :P

0

1 Answer 1

2

No, this is impossible. Primitives will always be passed by value while objects always passed by reference. There is nothing like * or &.

Sign up to request clarification or add additional context in comments.

2 Comments

Note: objects are passed by reference in that the function can modify (or even remove) properties of the object, but really it's by value in that the "value" is a copy of a reference to a specific object - if, inside the function, you try to change the reference to point to a different object the variable outside the function will continue to point to the original object. (OK, I know I got myself in a bit of a tangle trying to explain that in a comment where I couldn't give an effective code example.)
Strictly, all variables are "passed by value", where the value can be a primitive or a reference to an object.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.