-2

I have object like this :

var item = {
 A : 3,
 B : 4,
 C : parseInt(A*B)
}

I want to perform multiplication, C = A*B , i have tried to do multiplication as specfied in above object but did not work . How can i do that . Please help me

Ajit Soman
  • 3,586
  • 2
  • 21
  • 40
Thanh Tùng
  • 115
  • 1
  • 1
  • 7

1 Answers1

-2

You could reach the desired result with a simple function.

var item = {
 A : 3,
 B : 4,
 C : function() {
       return this.A * this.B;
     }
}

console.log(item.C());
kind user
  • 34,867
  • 6
  • 60
  • 74
  • Then you can't access `c` like a regular property, `C` is now a function. Evern though I did not give you the -1 – Dummy Apr 23 '17 at 11:07