Is Object.getPrototypeOf(val).toString() safe to ensure DOM types?
<p>I am writing a piece of library code for internal development at my company, so this is purely a personal satisfaction question - if there are issues, our error logging will note it pretty quickly and we'll be able to do updates...  I'd just like to avoid those if possible :D</p>

<p>The library needs to operate on <code>&lt;th&gt;</code> or <code>&lt;td&gt;</code> values passed in that are either sourced from <code>document.get...</code>, <code>document.createElement</code> or <code>onmousedown</code> events.  I've had issues when the wrong sort of object (i.e. non-<code>th</code>/<code>td</code>) went into the function, so I've put a fail-out clause at the top of the function:</p>

<pre><code>function doSomething (cell) {
    var _objName = Object.getPrototypeOf(cell).toString();
    if (_objName.indexOf("HTMLTableCellElement") === -1 &amp;&amp;
        _objName.indexOf("HTMLTableHeaderCellElement") === -1) {
        // log error
        return false;
    }

    // normal work here
}
</code></pre>

<p>Is this safe?  I'm targetting modern (IE 10+, Chrome) browsers within our company, and it seems to work at the moment:</p>

<ul>
<li>IE returns <code>"[object HTMLTableCellElementPrototype]"</code> (For <code>&lt;TD&gt;</code>) or <code>"[object HTMLTableCellHeaderElementPrototype]"</code> (for <code>&lt;TH&gt;</code>)</li>
<li>Chrome returns <code>"[object HTMLTableCellElement]"</code> for both</li>
</ul>

<p>I'm concerned that I'm relying on a non-documented implementation detail and things are going to break when we move to other browsers or browsers are updated.</p>

<p>Is this safe, or should I be using another method to ensure correct input?  Some of this input is going to be from things the user has clicked on, so there definitely will be invalid input going to the function...</p>