-2

I'd like to define a javascript object in which the value of a key depends on the value of another, like so :

var params = {
    width : 100,
    margins : 10,
    realWidth : width - margins
}

If I try this I get an error about width not being defined. Is it even possible to do that ?

GuitarExtended
  • 787
  • 2
  • 11
  • 32

1 Answers1

0

Set it using the dot notation

var params = {
    width : 100,
    margins : 10,
    realWidth : 0
}
params.realWidth=params.width - params.margins
console.log(params)
ellipsis
  • 12,049
  • 2
  • 17
  • 33