Skip to content

Commit

Permalink
fix for all IEs: no f.name
Browse files Browse the repository at this point in the history
  • Loading branch information
James Halliday committed Jul 26, 2013
1 parent 6b7d611 commit 4e0c2f6
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ module.exports = function inspect_ (obj, opts, depth, seen) {
return "'" + obj.replace(/(['\\])/g, '\\$1') + "'";
}
else if (typeof obj === 'function') {
return '[Function' + (obj.name ? ': ' + obj.name : '') + ']';
var name = nameOf(obj);
return '[Function' + (name ? ': ' + name : '') + ']';
}
else if (typeof HTMLElement !== 'undefined' && obj instanceof HTMLElement) {
var s = '<' + String(obj.tagName).toLowerCase();
Expand Down Expand Up @@ -76,3 +77,9 @@ function has (obj, key) {
if (!{}.hasOwnProperty) return true;
return {}.hasOwnProperty.call(obj, key);
}

function nameOf (f) {
if (f.name) return f.name;
var m = f.toString().match(/^function\s*([\w$]+)/);
if (m) return m[1];
}

0 comments on commit 4e0c2f6

Please sign in to comment.