Bug 1897150 Comment 13 Edit History

Note: The actual edited comment in the bug view page will always show the original commenter’s name and original timestamp.

It looks like this is the code that's going wrong:
```
this.ClosureDataTables = {
	"fn": function(){},
	"data": aoData,
	"sort": _oExt.oSort,
	"master": oSettings.aiDisplayMaster.slice()
};
var sDynamicSort = "this.ClosureDataTables.fn = function(a,b){"+
	"var iTest, oSort=this.ClosureDataTables.sort, "+
	"aoData=this.ClosureDataTables.data, "+
	"aiOrig=this.ClosureDataTables.master;";

for ( i=0 ; i<aaSort.length-1 ; i++ )
{
	iDataSort = oSettings.aoColumns[ aaSort[i][0] ].iDataSort;
	iDataType = oSettings.aoColumns[ iDataSort ].sType;
	sDynamicSort += "iTest = oSort['"+iDataType+"-"+aaSort[i][1]+"']"+
		"( aoData[a]._aData["+iDataSort+"], aoData[b]._aData["+iDataSort+"] ); if ( iTest === 0 )";
}

if ( aaSort.length > 0 )
{
	iDataSort = oSettings.aoColumns[ aaSort[aaSort.length-1][0] ].iDataSort;
	iDataType = oSettings.aoColumns[ iDataSort ].sType;
	sDynamicSort += "iTest = oSort['"+iDataType+"-"+aaSort[aaSort.length-1][1]+"']"+
		"( aoData[a]._aData["+iDataSort+"], aoData[b]._aData["+iDataSort+"] );"+
		"if (iTest===0) "+
			"return oSort['numeric-asc'](jQuery.inArray(a,aiOrig), jQuery.inArray(b,aiOrig)); "+
		"return iTest;}";
	
	/* The eval has to be done to a variable for IE */
	eval( sDynamicSort );
	oSettings.aiDisplayMaster.sort( this.ClosureDataTables.fn );
}
```
Which is weird, because it looks like we're somehow going wrong in code that boils down to:
```
this.closureDataTables = { fn: function() {} };
var sDynamicSort = "this.closureDataTables.fn = ..."
eval(sDynamicSort);
```
...because inside the eval we don't see a closureDataTables property on `this`.
It looks like this is the code that's going wrong:
```
this.ClosureDataTables = {
	"fn": function(){},
	"data": aoData,
	"sort": _oExt.oSort,
	"master": oSettings.aiDisplayMaster.slice()
};
var sDynamicSort = "this.ClosureDataTables.fn = function(a,b){"+
	"var iTest, oSort=this.ClosureDataTables.sort, "+
	"aoData=this.ClosureDataTables.data, "+
	"aiOrig=this.ClosureDataTables.master;";

for ( i=0 ; i<aaSort.length-1 ; i++ )
{
	iDataSort = oSettings.aoColumns[ aaSort[i][0] ].iDataSort;
	iDataType = oSettings.aoColumns[ iDataSort ].sType;
	sDynamicSort += "iTest = oSort['"+iDataType+"-"+aaSort[i][1]+"']"+
		"( aoData[a]._aData["+iDataSort+"], aoData[b]._aData["+iDataSort+"] ); if ( iTest === 0 )";
}

if ( aaSort.length > 0 )
{
	iDataSort = oSettings.aoColumns[ aaSort[aaSort.length-1][0] ].iDataSort;
	iDataType = oSettings.aoColumns[ iDataSort ].sType;
	sDynamicSort += "iTest = oSort['"+iDataType+"-"+aaSort[aaSort.length-1][1]+"']"+
		"( aoData[a]._aData["+iDataSort+"], aoData[b]._aData["+iDataSort+"] );"+
		"if (iTest===0) "+
			"return oSort['numeric-asc'](jQuery.inArray(a,aiOrig), jQuery.inArray(b,aiOrig)); "+
		"return iTest;}";
	
	/* The eval has to be done to a variable for IE */
	eval( sDynamicSort );
	oSettings.aiDisplayMaster.sort( this.ClosureDataTables.fn );
}
```
Which is weird, because it looks like we're somehow going wrong in code that boils down to:
```
this.closureDataTables = { fn: function() {} };
var sDynamicSort = "this.closureDataTables.fn = ..."
eval(sDynamicSort);
```
...because inside the eval we don't see a closureDataTables property on `this`.

Edit: Poking at it in the debugger, it seems like `this` is the number 1 here somehow? That seems like a problem.

Back to Bug 1897150 Comment 13