As Daniel said there is no way, the way is to pass an arrangement or object. Other ideas:
Name the variable
Problem : only works for global variables
var a=3;
function llamada(refVarGlobal){
global[refVarGlobal]++;
}
console.log(a); // 3
llamada("a");
console.log(a); // 4
Pass name and container
Problem : can not be local. You can only pass object properties, fix positions and global
var a=3;
function llamada(contenedor, refVar){
contenedor[refVarGlobal]++;
}
console.log(a); // 3
llamada(global, "a");
console.log(a); // 4
function ClaseMia(){
this.b=5;
this.incrementar = function(){
llamada(this, "b");
}
}
var c = new ClaseMia()
console.log(c.b); // 5
c.incrementar();
console.log(c.b); // 6
function comun(){
var contenedor = { e: 7 };
var arreglo = [8];
llamada(contenedor,"e");
llamada(arreglo,8);
}
Use a special reference object
Problem : Only variables of the Ref class can be passed as reference.
function Ref(valorInicial){
this.valor = valorInicial;
}
function llamada(ref){
ref.valor++;
ref.toString = function(){
return ref.valor;
}
}
var a = new Ref(3);
console.log(a); // 3
llamada(a);
console.log(a); // 4