# Global and local variables

This paragraph is neither specific to dFrameAPI nor to Javascript but to all languages:

In this code

//declare a global variable

var myVar

function myFunction() {

var myVar = 'something'

}

alert(myVar)

the myVar variable set in myFunction is of course a local one and the result will be 'undefined'.

Effects on dFrameAPI:

## DFrame instantiation:

First case:

var baseAll

DFrameAPI.onLoad=function() {

var baseAll = new DFrame(parameters)

…

}

function createDFrame() {

var dFrame = new DFrame(position, title, dFrameStyle, baseAll)

…

}

The DFrame dFrame will be created on the window browser object and not on baseAll as baseAll was declared as local in its instantiation.

The sub-DFrame (the one created on baseAll for instance) will have wrong dimensions (this can be useful to check if DFrames are correctly created in their parents).

When you click on the parent DFrame (baseAll for instance) it does not show the DFrame that are supposed to be its children.

Second case:

var dFrame

function createDFrame() {

if (!dFrame) {

var dFrame = new DFrame(position, title, dFrameStyle, baseAll)

…

}

}

Effects: A new DFrame is created each time.

## Style inheritance:

var barStyle

DFrameAPI.onLoad=function() {

…

var barStyle = new BarStyle()

…

}

function createBar() {

…

var bar = dFrame.addBar(barStyle)

…

}

The Bar bar will be created with the defaultBar of dFrame and not barStyle as barStyle was declared as local.