Not to be intentionally pedantic, but we are here to discuss things like coding conventions.
I find myself disliking how you switch from one style to another within the same method.
if (o === n) {
return 'null';
}
/*********
* If we made it this far, just return the set the
* r variable and return at the end;
*********/
switch (o) {
case g:
r = 'global';
break;
case g.document:
r = 'htmldocument';
break;
default:
break;
}
This switch statement could be written (shorter) as two if statements (and the comments add nothing to the function).
The r
variable is unnecessary (anywhere it is used can be replaced with a return statement).
The rest of the variables within that function are constants WRT it.
I would rewrite this whole thing like so:
/*jslint maxerr: 50, indent: 4 */
(function (g, Object, n, u) {
"use strict";
var nodeType = {
1: 'element_node',
2: 'attribute_node',
3: 'text_node',
4: 'cdata_section_node',
5: 'entity_reference_node',
6: 'entity_node',
7: 'processing_instrction_node',
8: 'comment_node',
9: 'document_node',
10: 'document_type_node',
11: 'document_fragment_node1',
12: 'notation_node'
};
Object.typeOf = function (o) {
if (o === u) {
return 'undefined';
}
if (o === n) {
return 'null';
}
if (o === g) {
return 'global';
}
if (o === g.document) {
return 'htmldocument';
}
if (o.nodeType && nodeType[o.nodeType]) {
return nodeType[o.nodeType];
}
return ({}).toString.call(o).match(/\s([a-z|A-Z]+)/)[1].toLowerCase();
};
}(this, Object, null));