Using __dt_wrapper to determine if an object is a DataTable object...fragile?
Using __dt_wrapper to determine if an object is a DataTable object...fragile?
I'm using this code to determine whether a given variable is referencing a DataTable object or not:
if(undefined != myObjectVariable.$ && myObjectVariable.$.__dt_wrapper) {
alert('A DataTable Object');
} else {
alert('Not a DataTable Object');
}
Since __dt_wrapper
is an undocumented internal, I'm wondering how robust this is: might it not be around in future versions? I'm also concerned that there might be a set of variables where myObjectVariable.$
is defined, but myObjectVariable.$.__dt_wrapper
is not or is false. (I don't really understand what the $
is about.) Is there a better way to do this?
This question has accepted answers - jump to:
Answers
This looks like a duplicate of this github issue that was filed yesterday.
The answer is to simply use the
instanceof
operator:myVar instanceof $.fn.dataTable.Api
.Allan
Wow. We must have been on the same psychic wavelength! Thanks Allan. I tinkered with
instanceof
for a while, but never came up with thefn
part of it. Will this work with bothDataTable
anddataTable
?$.fn.dataTable.Api
is the same as$.fn.DataTable.Api
.If you mean
$().dataTable()
, that is a jQuery instance so you would usex instanceof $
.Allan