While debugging some code that passes a function pointer to efsInternal (not as its first parameter) I realized there was a problem when creating two series. Specifically, it seems that under certain circumstances the second series to be created always contains the first series' values.
I whittled my original code down to the test code that follows, plus I added a few extra test cases. I would be appreciative if anybody could tell me why the two approaches that don't seem to work display their horizontal lines on top of each other instead of separately? I.e. why do their series have the same values? Thx.
Jeff
I whittled my original code down to the test code that follows, plus I added a few extra test cases. I would be appreciative if anybody could tell me why the two approaches that don't seem to work display their horizontal lines on top of each other instead of separately? I.e. why do their series have the same values? Thx.
Jeff
PHP Code:
function preMain()
{
var fp = new FunctionParameter("approach", FunctionParameter.STRING);
fp.addOption("doesntwork");
fp.addOption("doesntworkeither");
fp.addOption("butthisworks");
fp.addOption("andthisworkstoo");
fp.setDefault("doesntwork");
}
var series1 = null;
var series2 = null;
var fullyInitialized = null;
function main(approach)
{
if (!fullyInitialized)
{
if (approach == "doesntwork")
{
if (series1 == null)
series1 = efsInternal("functionProxy", regurgitate, [1]);
if (series2 == null)
series2 = efsInternal("functionProxy", regurgitate, [2]);
}
else if (approach == "doesntworkeither")
{
if (series1 == null)
series1 = efsInternal("functionProxy", regurgitate, [1]);
if (series2 == null)
series2 = efsInternal("functionProxy", anotherRegurgitate, [2]);
}
else if (approach == "butthisworks")
{
if (series1 == null)
series1 = efsInternal("functionProxy", regurgitate, [1]);
if (series2 == null)
series2 = efsInternal("anotherFunctionProxy", regurgitate, [2]);
}
else if (approach == "andthisworkstoo")
{
if (series1 == null)
series1 = efsInternal("regurgitate", 1);
if (series2 == null)
series2 = efsInternal("regurgitate", 2);
}
else
{
throw "oops!";
}
fullyInitialized = true;
}
if (getCurrentBarIndex() == -4)
{
debugPrintln(approach);
debugPrintln(" series1 = " + series1.getValue(0));
debugPrintln(" series2 = " + series2.getValue(0));
}
return [series1.getValue(0), series2.getValue(0)];
}
function functionProxy(functionPtr, args)
{
return functionPtr.apply(null, args);
}
function anotherFunctionProxy(functionPtr, args)
{
return functionPtr.apply(null, args);
}
function regurgitate(arg)
{
return arg;
}
function anotherRegurgitate(arg)
{
return arg;
}
Comment