function Method1(a, b, c) {
this.a = a;
this.b = b;
this.c = c;
}
Method1.prototype = {
add: function() {
let x = this.a * Method2.r + this.b + this.c;
console.log(x);
}
}
function Method2(a, b, c, r) {
this.r = r;
this.obj = new Method1(a, b, c);
}
Method2.prototype = {
print: function() {
this.obj.add();
}
}
let x = new Method2(1, 2, 3, 4);
x.print();
In the above sample code, I want to use the variable r of Method2 inside of Method1's add function. Can anyone please tell me where I am doing wrong and how to solve this? I need to access r inside add()