0

Is there a way to give a reference to a variable as a function / object parameter?

Example:

function Character(name,age,...){
  this.name = name;
  this.age = age;
  ...
}

function Something(age){
  this.age = age;
}

When i run code below:

var a = new Character('John', 23);
var b = new Something(a.age);//with reference
var c = new Something(33);//without reference

a.age++; 
//a.age is now = 24 but b.age is still 23

Is there a way to make a reference to a variable and give this as parameter?

//sorry for my bad english.

Łukasz Rząsa
  • 171
  • 3
  • 10

0 Answers0