0

I am a beginner in javascript, and I am wondering why this does not work? Any help would be much appreciated. Browser complains: Cannot read property 'size' of undefined

var settings = {

    size: {
            canvasWidth: 480,
            canvasHeight: 300,
            margin: {
                    top: 40,
                    bottom: 40,
                    left: 75,
                    right: 50
            },
            chartWidth: settings.size.canvasWidth - settings.size.margin.left - settings.size.margin.right
                ,
            chartHeight: settings.size.containerHeight - settings.size.margin.top - settings.size.margin.bottom

    }
}
KML
  • 2,302
  • 5
  • 26
  • 47
  • you are trying to use `settings` variable, within it's own declaration, before it's declaration gets completed. This is similar to `var i= i.length+ "abc";` where it will complain `i` is not defined – Amit.rk3 Aug 06 '15 at 14:13
  • Yes, but I find it strange that would not work, it should be self aware – KML Aug 06 '15 at 14:14
  • 1
    Instead of `settings.size` you should use `this`. Both `chartWIdth` and `chartHeight` should be methods returning the calculated value. This has also the advantage that by calling the method you always get the actual value, because the values for `margin` and the other members can change during the runtime of the program. – cezar Aug 06 '15 at 14:34

0 Answers0