I'm working with a mix of legacy code that uses the jQuery DataTables plugin (version 1.10. Some of the old code passes around jQuery object, and some of the old code passes around DataTables API objects. I'd like to make all new code accept either a jQuery object or a DataTables API object, but I haven't been able to detect when a variable refers to a DataTables API object.
The only detection method I could find in the API, isDataTable, is not suitable - it take a string selector for a table and returns whether the selection has been turned into a DataTable.
The "class detection" methods in this answer don't work; typeof
returns "object"
, constructor.name
returns "Object"
, and I don't know of a constructor to use for instanceof
or isPrototypeOf
.
As suggested in this answer (to same question), Object.prototype.toString.call(var)
returns "[object Object]"
In Chrome, console.log(var)
produces a summary that looks like it has some other class information:
▶ _Api {context: Array[1], selector: Object, ajax: Object}
I imagine that means there is something I could use somewhere but this question about where Chrome gets that name has no useful answers.
How can I detect when a variable refers to a jQuery-DataTables API object?