-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,926
  • 3
  • 22
  • 41
Thanh Tùng
  • 123
  • 1
  • 2
  • 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
  • 40,029
  • 7
  • 67
  • 77
  • Then you can't access `c` like a regular property, `C` is now a function. Evern though I did not give you the -1 – Trash Can Apr 23 '17 at 11:07