Could you propose any workarounds to implement a reference to variable using closures or any other tricks?
createReference = function() {
// TODO: how to
Only non-scalar types can be passed as reference, and will always be passed as reference:
var reference = {};
my_function(reference);
console.log(reference); // will show property - a property value
function my_function(my_reference) {
my_reference.property = "a property value";
}
var not_a_reference = [];
my_function(not_a_reference);
console.log(not_a_reference); // will NOT show 'a value'
function my_function() {
my_reference.push("a value");
}
Closer to your example:
function show(value) {
alert(value.data);
}
var value = { 'data': 5 };
show(value); // alerts 5
value.data = 6;
show(value); // alerts 6